Shutdown/Restart
shutdown command
The shutdown command can
safely shut down
or restart the system
hint:
1. Do not specify options and parameters, the default means to turn off the
1 minute
2. When maintaining the server remotely, it is better not to shut down the system, but to restart the system
Common Command Examples
View or configure network card information
Network card and IP address
network card
A network card is a hardware device dedicated to network communication
IP address is the address information set on the network card
We can compare a
computer
to a
phone
, a
network card
is equivalent to a
SIM card
, and
an IP address
is equivalent to
a phone number
IP address
Each networked computer has an IP address, which is an important setting to ensure normal communication between computers.
Note: The Ip address of each computer cannot be the same, otherwise there will be an Ip address conflict, and there is no way to communicate normally
ifconfig command
ifconfig can view/configure the current network card configuration information of the computer
Tip: There may be one physical network card and multiple virtual network cards in
a
computer . In Linux, the name of the physical network card is usually represented by ensXX
127.0.0.1
is called the
local
loopback/loopback address , which is generally used to test whether the local network card is normal
ping command
Ping is generally used to detect whether
the network is connected or not. The larger the value, the slower the speed.
ping is also often used as a verb among network administrators to ping a computer to see if it is on
Principle: All machines on the network have a unique IP address. We send a data packet to the target IP address, and the other party will return a data packet. According to the returned data packet and time, we can determine the existence of the target host.
Tip: In Linux, to terminate the execution of a terminal program, most of them can use CTRL+C
Remote login and copy files
ssh basics
SSH is a very common tool in Linux. Through the
SSH client,
we can connect to the remote machine running the
SSH server .
An SSH client is a software program that uses the Secure Shell (SSH) protocol to connect to a remote computer
SSH is currently the most reliable protocol for providing security
for remote login sessions and other network services
1. The use of SSH protocol can effectively
prevent information leakage during remote management
2. Through the SSH protocol, all transmitted data can be compressed, so the transmission speed can be accelerated
Domain name and port number
domain name
It consists of a
string
of names separated by dots, for example: www.baidu.com, which is an alias of the IP address, which is convenient for users to remember
The port number
IP Address
: Find a computer by its
IP address
Port number
:
The application running on the computer can be found through the port number
The default port number of the SSH server
is 22. If it is the default port number, it can be omitted when connecting.
List of common server port numbers:
Simple use of SSH client
user is the username on the remote machine, if not specified it defaults to the current user
remote is the address of the remote machine, which can be an IP/domain name , or an alias that will be mentioned later
port is the port that the SSH Server listens on . If not specified, the default value is 22.
hint:
Use exit to log out of the current user's login
Notice:
The ssh terminal command can only be used under Linux or UNIX systems
If you are in Windows system, you can install PuTTY or XShell client software.
hint:
At work, the port number of the SSH server is probably not 22. If you encounter this situation, you need to use the -p option to specify the correct port number, otherwise you cannot connect to the server normally.
Installation of SSH Client under Windows
Putty:https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
XShell:https://www.netsarang.com/products/xsh_overview.html
scp command
scp is secure copy, which is a command used to copy files
remotely
Its address format is basically the same as ssh. It
should be noted that when specifying the port, uppercase -P is used
instead of lowercase
Notice:
The scp terminal command can only be used under Linux or UNIX systems. If you are in Windows systems, you can install PuTTY, use the pscp command line tool or install FileZilla for file transfer using FTP
FileZilla uses FTP service instead of SSH service when transferring files, so the port number should be set to 21
SSH Advanced
Tip: The SSH configuration information is saved in the .ssh directory under the user's home directory
1) Password-free login
step
Configure public key: Execute ssh-keygen to generate SSH key, just press Enter all the way
Upload the public key to the server: execute ssh-copy-id -p port user@remote, the remote server can remember our public key
Schematic
Asymmetric encryption algorithm
Data encrypted with the
public key
needs to be decrypted with the private key
Data encrypted with the
private key
needs to be decrypted with the public key
2) Configure aliases
Entering ssh -p port user@remote every time will feel very troublesome after a long time, especially when user, remote and port have to be entered, and it is not easy to remember, and configuring aliases can make us further lazy, such as using: ssh mac to replace the long list above, then add the following to ~/.ssh/config:
After saving, you can use ssh mac to achieve remote login, and scp can also be used