content

  • Shutdown/restart
    • shutdown
  • View or configure nic information
    • ifconfig
    • ping
  • Remotely log in and copy files
    • ssh
    • scp

1. Power off or restart

The serial number The command Corresponding English role
01 Shutdown option time shutdown Shut down/restart

1.1 shutdown

  • shutdownCommand canShut down safelyorRestart the system
options meaning
-r Restart the

Tip:

  • If no option or parameter is specified, the computer will be shut down after 1 minute by default
  • When maintaining a server remotely, it is best not to shut down the system, but to restart it
  • Examples of Common Commands
Restart the operating system, where now stands for now
$ shutdown -r now

Shut down the machine now
$ shutdown now

The system will shut down at 20:25 today
$ shutdown 20:25

The system will automatically shut down in 10 minutes
$ shutdown +10

Cancel the shutdown plan specified earlier
$ shutdown -c
Copy the code

2. View or configure nic information

The serial number The command Corresponding English role
01 ifconfig configure a network interface View/configure the current network adapter configuration information of the computer
02 Ping the IP address ping Check whether the connection to the destination IP address is normal

3. The command

3.1 the ifconfig

  • ifconfigYou can view/configure the current network adapter configuration information of the computer
Check the nic configuration
$ ifconfig

Check the IP address of the nic
$ ifconfig | grep inet
Copy the code

Note: A computer may have one physical nic and multiple virtual nics. In Linux, the name of a physical NIC is ensXX

  • 127.0.0.1Referred to asLocal loopback/loopback addressIs generally used to test whether the local network adapter is normal

3.2 the ping

Check whether the target host is properly connected$ping IP addressCheck that the local NIC works properly$ping 127.0.0.1Copy the code
  • pingGenerally used to detect the network between the current computer and the target computerWhether it is unobstructed, the higher the value, the slower the speed

Ping works in a similar way to a submarine’s sonar, and is often used as a verb among network administrators — ping computer X to see if it’s on

Principle: All the machines on the network have a unique IP address, we send a packet to the destination IP address, the other party will return a packet, according to the returned packet and the time, we can determine the existence of the target host

Tip: In Linux, if you want to terminate the execution of a terminal program, you can almost always use CTRL + C

3.3 Remote Login and File Replication

The serial number The command Corresponding English role
01 SSH username @IP secure shell Shut down/restart
02 SCP username@ip: file name or path Username@ip: file name or path secure copy Remote File Replication

3.4 basis of SSH

SSH is a very common tool in Linux, through the SSH client we can connect to the remote machine running SSH server

  • SSH clientIs a kind of useSecure Shell (SSH)Protocol A software program that connects to a remote computer
  • SSHIt is currently a reliable protocol designed to provide security for remote login sessions and other network services
    • usingSSH protocolCan be effectivelyPrevent information leakage during remote management
    • throughSSH protocolEncrypts all transmitted data and prevents DNS spoofing and IP spoofing
  • SSHAnother advantage is that the transmitted data can be compressed, so the transmission speed can be increased

The default port number of the SSH server is 22. If it is the default port number, you can omit it during connection

List of common service ports:

The serial number service The port number
01 SSH server 22
02 The Web server 80
03 HTTPS 443
04 The FTP server 21
ssh [-p port] user@remote
Copy the code
  • userIs the user name on the remote machine, which defaults to the current user if not specified
  • remoteIs the address of the remote machineIP/The domain name, or theThe alias
  • portPort monitored by the SSH ServerIf this parameter is not specified, the default value is 22

Tip:

Use exit to log out of the current user.

  • SSH This terminal command can be used only in Linux or UNIX
  • In Windows, you can install PuTTY or XShell

Tip:

  • At work, the port number of the SSH server is likelyNot 22If this is the case, use it-pOption to specify the correct port number, otherwise the server cannot be connected properly

Install the SSH client in Windows

  • Putty
  • XShell recommends downloading the official installation program from the official website

3.5 the SCP

  • scpissecure copy, is a inLinuxUsed to carry onCopying files remotelyThe command
  • It’sNote that the address format is basically the same as that of SSHIs uppercase when specifying the port-PNot lowercase

# copy the 01.py file in the current local directory to Desktop/01.py in the remote home directory
If the path following: ':' is not an absolute path, the user's home directory is used as a reference path
scp -P port 01.py user@remote:Desktop/01.py

Copy the Desktop/01.py file in the remote home directory to 01.py in the current local directory
scp -P port user@remote:Desktop/01.py 01.py

# add the -r option to transfer folders
Copy the demo folder in the current directory to the Desktop in the remote home directory
scp -r demo user@remote:Desktop

Copy the Desktop in the remote home directory to the demo folder in the current directory
scp -r user@remote:Desktop demo
Copy the code
options meaning
-r If the source file given is a directory file, the SCP recursively copies all subdirectories and files under that directory, and the target file must be a directory name
-P If the port number of the remote SSH server is not 22, use the uppercase -p option to specify the port number

Note:

SCP This terminal command can be used only in Linux or UNIX. In Windows, you can install PuTTY, use the PSCP command line tool, or install FileZilla to transfer files through FTP

FileZilla

FileZilla uses the FTP service instead of the SSH service to transfer files, so the port number should be set to 21

4. The senior SSH

  • Password-free login
  • Configure an alias

Tip: All SSH configuration information is saved in the.ssh directory of the user’s home directory

4.1 Password-free Login

steps
  • Configure the public key
    • performssh-keygenTo generate an SSH key, press Enter
  • Upload the public key to the server
    • performssh-copy-id -p port user@remoteTo make the remote server remember our public key

Schematic diagram

Asymmetric encryption algorithm

  • Data encrypted using a public key needs to be decrypted using a private key
  • Data encrypted using the private key needs to be decrypted using the public key

4.2 Configuring An Alias

SSH -p port user@remote is not easy to remember, especially when user, remote and port have to be entered

SSH /.ssh/config to add the following: /.ssh/config

Host MAC HostName IP address User XXZX Port 22Copy the code

After saving, you can use SSH MAC to achieve remote login, SCP can also be used