Centos basic commands

  1. Linux machines log in to each other
First generate the public key and private key on the server, use the command: ssh-keygen

[ root@linux-01~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key(/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase(empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in/root/.ssh/id_rsa.
Your public key has been saved in/root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:3FYV0kj/2uk/L28tqNL/XGuYcwBCrrNDH2SR4SkaDDk root@linux-01
The key's randomart image is:+---[RSA 2048]----+|...o.ooo.||   Eo   .+..+.||.o .oo...||      o..* o   .||.  S +..||+ o   . o.||.+...=.+||       o....=+=+||...o..*BB|+----[SHA256]-----+

The private key is:/root/.ssh/id_The rsa public key is:/root/.ssh/id_rsa.pub

The direct secret-free login of two servers requires the public key to be placed on another server. The file location is:~/.ssh/authorized_keys 

There is a command to automatically copy the public key to the other's machine, the command is: ssh-copy-id  

[ root@linux-01~]# ssh-copy-id [email protected]/usr/bin/ssh-copy-id: INFO: Source ofkey(s) to be installed:"/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.145.130 (192.168.145.130)' can't be established.
ECDSA key fingerprint is SHA256:5GxiNdyl0UuM/kthNV2MtFRMyoZ5myCf7VbrK5Z04Sw.
ECDSA key fingerprint is MD5:f0:8f:2e:df:87:18:60:1f:aa:9d:ee:ba:a8:56:75:d2.
Are you sure you want to continueconnecting(yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log inwith the newkey(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO:1key(s) remain to be installed --if you are prompted now it is to install the newkeys
[email protected]'s password:

Number ofkey(s) added:1

Now try logging into the machine,with:"ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
  1. Analysis of the role of each directory in centos
/root/ #User Home Directory
/bin//usr/bin//sbin//usr/sbin/ #The commands in the bin directory are commands for ordinary users, and the commands in the sbin directory are commands for super users.
/boot/ #System startup related files
/dev/ #Device file
/etc/ #System configuration file
/home/ #User home directory file
/lib//lib64/ #Library file
/media/ #Media folder such as: U disk
/mnt/ #Default empty mount U disk drive
/opt/ #Default empty
/proc/ #process
/run/ #Temporary files generated by the process, restart and disappear
/srv/ #Files generated by the empty storage service
/sys/ #System kernel related files
/tmp/ #Temporary directory
/usr/ #User's file
/var/ #Log
  1. Basic commands
Common options of the ls command:
- a Show all files including hidden files
- l Display the detailed information of the file
- h Display file size, size with unit
- t Display files in chronological order
- d Only display folders

alias command
The function of this command is an alias. We can use aliases when typing a long command, which makes it convenient for us to use the command

tree command: tree display directories and files
[ root@linux-01~]# tree /root//root/
├── 11.txt
├── 22.txt
└── anaconda-ks.cfg

0 directories,3 files	

man command: you can view the help file of the command

cd command: enter a directory

pwd command; display the current directory

history command: display historical usage commands

wc -l Command: How many lines are in the statistics file

mkdir command: the command to create a folder, if you need to create it level by level, you need to add options-p

rmdir command: It is the opposite operation to the mkdir command, which is a command to delete a folder. If there are files in the file, you need to add options-p
rm command: delete command
- f Force deletion of files
- r delete directories recursively
- v Show the delete process

cp command: the command to copy files, and at the same time, you can change the name. When copying to the target directory, you can directly modify the file name.
- r Need to add when copying multi-level directories

mv command: a command to move files, and it can also be renamed

cat command: command to view files
- n Add line numbers when viewing files

tac command: flashback to view the file command

More command: Use when the file cannot be displayed in one screen, press the space to display the content of the next screen, ctrl+b Previous screen.

less command: single screen display, look down in the space, Ctrl+b Look up, support up and down keys, Ctrl+b Look up, you won’t quit after reading, you need to press q to quit

head command: display the content of the first few lines of the file, cooperate-n Add numbers to use.

tail command: you can dynamically view the contents of the file, cooperate-f to use, mostly used to view log files.

chmod command: command to add permissions to files and folders, you need to add it when you need to recurse-R option

chown command: a command to change the owner and group of files and folders. Format: chown-R username:group filename   

umask: used to determine the default permissions for creating directories and files, the root user defaults to; 0022 permissions
chattr command: a command to add hidden permissions to a file
Adding an i permission to the file can be realized: the file cannot be edited, cannot be appended, cannot be renamed, cannot be deleted, cannot report errors, and cannot be touched. (Touch will change the creation time of the file) The command is: chattr+i  11.txt If you don’t want this i permission, you can use the command chattr-i  11.txt delete i permission.
Adding a permission to a file can be realized: it cannot be deleted, cannot be changed, cannot be renamed, the content of the file can be appended, and it can be touched. The command is: chattr+a  11.txt If you don’t want this a permission, you can use the command chattr-a  11.txt delete i permission.
The effect of adding an i permission to the directory is: can write existing files in the directory, cannot delete, cannot rename, and cannot create file directories under the directory.
The effect of adding a permission to the directory is: it can be appended but cannot be changed, it can be touched in the directory, and the content under the file can be changed

lsattr command: command to view file hidden permissions

ln command: hard link,

ln -s command: soft connection, equivalent to windows shortcut, usage: ln-s source file target address file

which command: Find the location of the command

whereis command: The same is to find the location of the command, and find locate in the pre-prepared file library to the library. Not commonly used locate installation: yum install-y mlocate locate usage: locate+file name/The command first needs to traverse the file to generate the database to generate the database command: updatedb

find command:
Format find directory parameters
find /-name "file name"Find a file
find /home/-type d -name "xxx"; Find the directory where the file is xxx in the home directory, the type can be the following type of file d: directory f: file l: soft connection s: sock file c: string file b: block device
find /-type f -mtime  -1(Within 1 day)+1 (more than 1 day)
find /etc/-type f -o -mtime -1-o -name "*.conf"-o means or
find /root/-type f -mmin -60-exec ls -l {};-The exec parameter is followed by the command command, which terminates with;It is the end sign, so the semicolon after this command is indispensable. Considering that the semicolon has different meanings in various systems, add a backslash in front.
  1. File attributes
We know that all the information on linux is a file. What are the file types? Actually, it is in ls-When l, the first paragraph of information will tell us
- Normal file
d catalog file
b Fast file, such as hard disk, CD/DVD
l Soft connection file, equivalent to windows shortcut
s socket file, which is communication file
c String device, such as keyboard
  1. Absolute path and relative path
This is easy to understand, the absolute path is like an nginx.tar.gz file in/usr/local/src/under

Expressed as an absolute path:/usr/local/src/nginx.tar.gz

The relative path is expressed as: assuming that it is in the src directory, expressed as: nginx.tar.gz
  1. PATH environment variable
There is a system environment variable in linux, use echo$PATH can show the location of system variables

[ root@linux-01~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

We know that all user commands are stored in the sbin and bin directories. We can use these commands directly. If your commands are not in this PATH environment, then we need to add the commands to the PATH environment variable. How to add to environment variables?

This involves another file:/etc/profile, we need to add a line at the end of this file: export PATH=$PATH:/usr/local/nginx/bin/   

Assuming there are commands to be used in the bin directory of nginx, you can set it like this.
  1. Special permission
set_uid: It is to ensure that ordinary users temporarily own all the identity (temporary possession) must be a binary group, executable files such as/usr/bin/passwd,chmod u+s /usr/bin/ls Note: u is owner authority and larger S is because of lack of X authority, directory can add S authority but it is meaningless

set_gid: to ensure that ordinary users temporarily own the identity of the group (temporary possession) must be a binary group, executable files such as/usr/bin/ls, can act on the directory, when set to the directory_Files and directories created in the directory after gid will be consistent with the group of the parent directory

stick_bit: except to prevent others from deleting their own files (root),/tmp/You can change other people's files in the directory and cannot be deleted,/tmp/Directory is with stick_Bit permission, delete the file directory is to see the permissions of the parent directory
  1. Time atime, ctime, mtime
Access time =atime access time: the last time the data in the file was accessed
Modify time =mtime modification time: the last time the file content was modified
Change time =ctime Change time: The metadata of the file changes. Such as permissions, owners, etc.
  1. Command line mode shortcuts
Ctrl+l Clear screen
Ctrl+d Exit the terminal
Ctrl+c terminal task
Ctrl+u Delete the content before the cursor
Ctrl+e cursor to the end
Ctrl+a Move the cursor to the beginning

Recommended Posts

Centos basic commands
CentOS7 basic configuration
CentOS 8 (2)
Centos7 system commonly used commands
CentOS 8 (1)
CentOS 8 install Git and basic configuration
centos7 python3.7+vi
CentOS + Python3.6+
CentOS + Jenkins
1.5 Install Centos7
2019-07-09 CentOS7 installation
centos7_1708 installation
Centos 7.5 python3.6
Some Centos Python production environment deployment commands
Some basic optimizations of Centos6.9 system (updated on 2018/04/19)