Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Common skills of linux system

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "the common tips of the linux system". In the daily operation, I believe that many people have doubts about the common tips of the linux system. The editor consulted all kinds of materials and sorted out the simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "the common tips of the linux system". Next, please follow the editor to study!

+ + realize automatic disk repair of abnormal shutdown of RedHat

Log in to the server first, and then add a file autofsck to / etc/sysconfig, as follows:

AUTOFSCK_DEF_CHECK=yes

PROMPT=yes

+ + change the last modification time of a file or directory (become the current time)

Execution format: touch name (name can be a file or directory name.)

+ + how to set welcome information after login

Modify / etc/motd to write text into it.

+ + how to set up the welcome interface before login

Modify / etc/issue or issue.net to write text into it.

The content of issue appears in the user interface of local login, while issue.net appears when the user is through the network telnet.

+ + how to modify the MAC address of the network card

The network card device must be turned off first, otherwise the system will be reported to be busy and cannot be changed.

The command is: / sbin/ifconfig eth0 down

Modify the MAC address, which is easier than the modification in Windows.

The command is: / sbin/ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE

Re-enable the network card / sbin/ifconfig eht0 up

The MAC address of the network card is changed.

+ + create aliases / delete aliases

Alias cp='cp-i'

Unalias cp

+ + how to know what library files are used by a command

For example, to know what library files ls uses, you can use:

$ldd / bin/ls

+ + how to make a user process still run after the user exits the system

Use nohup command &, for example: nohup wget-c ftp://test.com/test.iso

# in this way, even if the user logs out of the system, the wget process continues to run until the test.iso download is complete

+ + how to limit the minimum password length of a user

Modify the value of PASS_MIN_LEN in / etc/login.defs. For example, limit the minimum password length to 8:

PASS_MIN_LEN 8

+ + how to cancel the history of root commands to increase security

To set up the system not to record commands that everyone has executed, set it in / etc/profile:

HISTFILESIZE=0

HISTSIZE=0

Or:

Ln-s / dev/null ~ / .bash_history

+ + how to test hard disk performance

Using hdparm-t-T / dev/hdX, you can test the buffer-cache reads and buffered disk reads data of the hard disk, which can be used as a reference for hard disk performance.

At the same time, using hdparm-c3 / dev/hdaX can also set the hard disk to 32bit transmission, in order to speed up the speed of data transmission.

+ + how to list the space occupied by a directory

Du or du-s or du-k

Du-S | sort-n can quickly find out which directory is the largest.

With df, you can see the size of the installed file system and the amount of space left.

Quota-v looks at the user's disk space information, if you use quota to limit the amount of user space.

+ + how to force new users to change their passwords after logging in for the first time

# useradd-p''testuser; chage-d 0 testuser

+ + sometimes the new hardware is not checked automatically when booting in Linux, and the newly installed network card cannot be found. Could you tell me how to solve it?

Answer: the service that automatically checks for new hardware is Kudzu, and users can start it with the "ntsysv" command. The next time you restart, you will find the user's new network card.

+ found from a website in Taiwan Province, how to make the system password consistent with the samba password, and allow users to change their passwords.

Use the web interface to synchronize changes to system passwd and samba password

Download http://changepassword.sourceforge.net/

Just install it. Take a look at README first.

Attach:

Convert system users into samba users in batches.

Less / etc/passwd | mksmbpasswd.sh >; / etc/samba/smbpasswd

+ + change whether Linux starts with a graphical interface or a character interface

Cd / etc

Vi inittab

Id:5:initdefault: where 5 represents the default graphical interface

Change id:3: initdefault: 3 to represent the character interface

+ + configure which IP smb can be used by.

Cd / etc/samba

Vi smb.conf

Find hosts allow = 192.168.1. 192.168.2. one hundred and twenty seven。

Modify which machines are used, and note that IP is separated by commas

For example:

Hosts allow = 192.168.1.110192.168.1.120

+ + prohibit the use of CTRL-ALT-DELETE to restart machines in the background

Cd / etc/inittab

Vi inittab found the following line in the file

# Trap CTRL-ALT-DELETE

Ca::ctrlaltdel:/sbin/shutdown-T3-r now (comment out this line)

For example: # Trap CTRL-ALT-DELETE

# ca::ctrlaltdel:/sbin/shutdown-T3-r now

+ + modify hostname

Vi / etc/sysconfig/network

Modify HOSTNAME-behavior HOSTNAME= hostname

+ + View the hardware detected by boot

Dmesg | more

+ + View the usage of hard disk

Df-m

+ + View the size of the directory

Du-sh dirname

+ + decompress Xiaoquan

Tar xvfj lichuanhua.tar.bz2

Tar xvfz lichuanhua.tar.gz

Tar xvfz lichuanhua.tgz

Tar xvf lichuanhua.tar

Unzip lichuanhua.zip

Note: compress tar cvfz FileName.tar.gz DirName

+ + display memory usage

Free-m

+ + shows how long the system has been running

Uptime

+ + display the contents of post command

Dmesg

Detailed list of + + ports

/ etc/services

+ + View physical information

Lspci

Chinese support for + + text section

RH 9.0 comes with the installation package zhcon_0.2.3_1.rh9.i386.rpm

After the installation is complete, execute: zhcon to support Chinese

+ + linux controls windows

(1) use RH9.0 to bring your own rdesktop, version 1.2.0

Command: rdesktop-u user-f 192.168.1.70 default is 8 bits

(2) to achieve 16 colors, you need to download the new version 1.3.0

Rdesktop-a 16-u lichuanhua-g 800mm 600 192.168.1.70

+ + do not let the monitor sleep

Setterm-blank 0

+ + displays the last user logged in to the system

Last

+ + View the last login time of all accounts

Lastlog / var/log/lastlog

+ + View the login time and place of all users since the system was launched

Cat / var/log/secure

+ + displays the information of the current user

Id

+ + how to know the number of connections to Apache

Ps-ef | grep httpd | wc-l # other services can be analogous

Netstat-nat | grep-I "80" | the result above wc-l # should be minus 1 more.

+ + when deleting a user's account, delete the user's home directory as well

Userdel-r user name

+ + modify the information of existing users

Usermod [parameter] user name

Parameters:-c,-d,-m,-g,-G,-s,-u and-o have the same meaning as adduser parameters

New parameter:-l new user name (specify a new account, change the original user name to a new user name)

+ + change redhat system language / character set

Change / etc/sysconfig/i18n file, such as

LANG= "en_US", xwindow will display the English interface

LANG= "zh_CN.GB18030", xwindow will display the Chinese interface.

There's another way.

Cp / etc/sysconfig/i18n $HOME/.i18n

Modify the $HOME/.i18n file, such as

LANG= "en_US", xwindow will display the English interface

LANG= "zh_CN.GB18030", xwindow will display the Chinese interface.

In this way, you can change a person's interface language without affecting other users.

Vi .bashrc

Export LANG=zh_CN.GB2312

Export LC_ALL=zh_CN.GB2312

+ + cd CD to make iso file

Cp / dev/cdrom xxxx.iso

+ + hardware detection of fast viewing boot

Dmesg | more

+ + View the usage of the hard disk

Df-k is displayed in K units

Df-h is displayed in a humanized unit, which can be bPercience, KJE, MJM, gJT.

+ + View the size of the directory

Du-sh dirname

-s displays only totals

-h take K, M, G as units to improve the readability of information. KB, MB and GB take 1024 as the conversion unit and-H as the conversion unit of 1000.

+ + find or delete a process that is using a file

Fuser filename

Fuser-k filename

In + + linux, the user's password must have a certain length and meet the complexity.

Vi / etc/login.defs, change to PASS_MIN_LEN

+ + run the program as a different user

Su-username-c "/ path/to/command"

Sometimes if you need to run a program with a special identity, you can let su do it.

+ + adduser m-g cvsroot-s / bin/false

Add user m. Parameter-s / bin/false means that users are not allowed to log in directly to the server.

Id m

Displays the uid and gid numbers of the m user.

+ + Force uninstall rpm package

Rpm-e-nodeps package name

# under some abnormal circumstances:

Rm-f / var/lib/rpm/__*

Rpm-rebuilddb

+ + deny login to users other than root users

Touch / etc/nologin

You can also add it to / etc/passwd! Restrict login to specified users

+ + check the name of the group you belong to

Execution format: groups

+ + modify the user group to which the file / folder belongs (support-R)

Chown. Group name file name (Note: group name do not forget ".", ":" may also)

You can also chgrp the group name file name

Chown user name. Group name file name (both the user and the user group are modified)

+ + use the fuser command to see which processes use the files on this partition:

Fuser-v-m / usr

If there are no important processes, stop them with the following command:

Fuser-k-v-m / usr

These file systems can then be remounted.

+ + the network wakes up the host

Ether-wake target network card MAC

+ + how to find files with sizes between 500K and 1000K

Find /-type f-size + 500k-and-size-1000k

+ + make the host not respond to ping

Echo 1 > / proc/sys/net/ipv4/icmp_echo_ignore_all

If you want to recover, use it.

Echo 0 > / proc/sys/net/ipv4/icmp_echo_ignore_all

# must be modified by command, not by vi

+ + automatically log out of ROOT

Edit your configuration file "vi / etc/profile" and add the following line after "HISTSIZE=":

TMOUT=300

# 300, which means 300 seconds

+ + ls lists only directories

Ls-lF | grep ^ d

Ls-lF | grep / $

Ls-F | grep / $

+ + keep cron tasks from giving back information

* cmd > / dev/null 2 > & 1

+ + lsof (list open files) usage

Lsof-I: xx

Lsof abc.txt shows the process of opening the file abc.txt

Lsof-I: 22 know what program port 22 is running now

Lsof-c nsd displays the files now opened by the nsd process

Lsof-g gid shows the process that belongs to the gid

+ + change the port of sshd

Add a line to / etc/ssh/sshd_config: Port 2222, Port 2222, reboot the daemon,

+ + prevent anyone from using the su command to become root

Vi / etc/pam.d/su, add the following two lines at the beginning:

Auth sufficient / lib/security/pam_rootok.so

Auth required / lib/security/Pam_wheel.so group=wheel

Then add the user to the "wheel" group: chmod-G10 username

+ + how to make ssh allow only specified users to log in

Method 1: add to the / etc/pam.d/sshd file

Auth required pam_listfile.so item=user sense=allow file=/etc/sshusers onerr=fail

Then set up the sshusers file under / etc, add the user name that allows the use of the ssh service (each user name needs a separate line), and restart sshd

+ + use ssh to copy files

1. Copy B from A (push) # scp-rp / path/filename username@remoteIP:/path

2. Copy from B to A (pull over) # scp-rp username@remoteIP:/path/filename / path

+ + linux machine mounts shared files on windows

Windows IP:192.168.1.1

Mount-t smbfs-o username=massky,password=massky / / 192.168.1.1/dbf / mnt/share

If you want to restart the machine to mount automatically, vi / etc/fstab is finally added:

/ / 192.168.1.1/dbf / mnt/share smbfs defaults,auto,username=massky,password=massky 0 0

+ + Custom linux prompt

In bash, the prompt is specified through an environment variable $PS1. Use export $PS1 to view the current value, which is straightforward

The commonly used prompt can be set to export PS1= "[\ u @\ h\ W]\ $". Where\ u represents the user name and\ h represents the host

Name,\ W represents the last layer of the current working directory, $is displayed for normal user\ $, and root user displays #.

+ + empty files

[echo] > file name

+ + DNS related

Host-a domain.com # shows that the relevant information is listed

Host domain.com 202.106.0.20 # query domain.com with the DNS server 202.106.0.20

+ + related to front and background tasks

Jobs lists the processes that belong to the current user

Bg moves the process to the background (Background)

Fg moves the process to the foreground (Foreground)

In case you forget to use "&" when you run the program, and you don't want to run it again. You can use ctrl+z to suspend the program, and then type the bg command so that the program continues to run in the background.

+ + find files from seven days ago in the current directory and delete them

Find. /-mtime + 7-type f-exec rm {}\

+ + produces a file of the specified size (bs*count)

Dd if=/dev/zero of=filename bs=1000000 count=10

+ + find the files in the current directory and change the extension

Change all .ss files to .aa

# find. /-name "* .ss"-exec rename .ss .aa'{}'\

+ + modify system time

Date-s "2005-6-4 17:26"

+ + Let the server synchronize the time automatically

0 1 * / usr/sbin/ntpdate 210.72.145.44

Or 0 1 * rdate-s time.nist.gov

At this point, the study of "common tips for linux systems" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report