6.1 ssh command – secure remote connection to server
6.1.1 Meaning
sshThe function of the command is to securely connect to the server host system remotely. As a client connection tool in the openssh suite, the sshcommand allows us to easily access the remote hostssh based on the encryption protocol , so as to realize the management of the remote server.
6.1.2 Syntax format
ssh [参数] 域名或 IP 地址
6.1.3 Common parameters
parameter
meaning
-1
Use ssh protocol version 1
-2
Use ssh protocol version 2
-4
Based on IPv4 network protocol
-6
Based on IPv6 network protocol
-a
Turn off the authentication proxy connection forwarding function
-A
Enable authentication proxy connection forwarding function
-b
Set the IP address of the machine to provide external services
-c
Set the password algorithm for the session
-C
compress all data
-f
Execute ssh commands in the background
-F
set configuration file
-g
Allow remote hosts to connect to this machine's forwarded port
-i
set key file
-l
Set login username
-N
Do not execute remote commands
-o
Set configuration parameter options
-p
Set the port number on the remote server
-q
silent execution mode
-s
request a subsystem call on a remote host
-v
Show Execution Details
-V
show version information
-x
Disable X11 forwarding function
-X
Enable X11 forwarding function
-y
Trust X11 forwarding functionality
6.1.4 Reference example
Based on sshthe protocol, remote access server host system:
ssh192.168.10.10
Log in to the remote server host system as the specified user:
ssh-l linuxprobe 192.168.10.10
Execute a command after logging in to the remote server host system:
ssh192.168.10.10 "free -m"
Forcibly use the v1 version of the ssh encryption protocol to connect to the remote server host:
ssh-1192.168.10.10
6.2 netstat command – display network status
6.2.1 Meaning
netstatThe command comes from network statisticsthe abbreviation of the English phrase, and its function is to display various network-related information, such as network connection status, routing table information, interface status, NAT, multicast members, and so on.
netstatThe command is not only applied to the Linux system, but also supported by default in Windows XP, Windows 7, Windows 10 and Windows 11, and the available parameters are the same, so experienced operation and maintenance personnel can get started directly.
6.2.2 Syntax format
netstat [参数]
6.2.3 Common parameters
parameter
meaning
-a
Display information about all connected interfaces
-A
Set network connection type
-c
Continuous display of network status
-C
Display routing configuration information
-F
show route cache information
-g
Display the list of multicast function group members
-h
show help information
-i
Show web interface information form
-l
Only show the status of services that are listening
-n
Use the IP address directly, not the domain name
-N
Display symbolic link names for network hardware peripherals
-o
Display timer data information
-p
Display the program ID and name of the interface being used
-r
display routing table information
-s
Display network work information statistics table information
-t
Display the connection status of the TCP transport protocol
-u
Display the connection status of the UDP transport protocol
-V
show version information
6.2.4 Reference example
Display all connection information in the system network status:
netstat-a
Display UDP connection information in system network status:
netstat-nu
Display the UDP connection port number usage information in the system network status:
netstat-apu
Display the current status information of the network card:
netstat-i
Display network routing table status information:
netstat-r
Find the connection information corresponding to a service:
netstat-ap|grepssh
6.3 dhclient command – dynamically obtain or release IP address
6.3.1 Meaning
dhclientThe command comes from the abbreviation of the English phrase DHCP client, and its function is to dynamically obtain or release an IP address. Before using dhclientthe command, you need to set the network card mode to DHCP to obtain automatically, otherwise the network card in static mode will not actively obtain network card information such as IP address from the server.
6.3.2 Syntax format
dhclient 参数 [网卡名]
6.3.3 Common parameters
parameter
meaning
-4
Based on IPv4 network protocol
-6
Based on IPv6 network protocol
-d
run in foreground
-F
Set the FQDN sent to the DHCP server
-H
Set the hostname sent to the DHCP server
-n
Do not configure any interface
-p
Set the port number the DHCP client listens on
-q
silent execution mode
-r
release IP address
-s
Specify a DHCP server before obtaining an IP address
mount 命令的功能是用于将文件系统挂载到目录,文件系统指的是被格式化过的硬盘或分区设备,进行挂载操作后,用户便可以在挂载目录中使用硬盘资源了。
默认情况下 Linux 系统并不会像 Windows 系统那样自动地挂载光盘和U盘设备,需要自行完成。
7.1.2 语法格式
mount [参数] [设备名] [目录名]
7.1.3 常用参数
参数
含义
-a
加载“/etc/fstab”文件中记录的所有文件系统
-F
为每个设备创建出一个新的挂载版本
-h
显示帮助信息
-l
显示已加载的文件系统列表
-L
挂载具有指定标签的分区
-n
加载没有写入“/etc/mtab”文件中的文件系统
-r
将文件系统设置为只读模式
-t
挂载指定文件类型的设备分区
-U
挂载指定 UUID 的设备分区
-V
显示版本信息
-w
以读写方式挂载文件系统
7.1.4 参考示例
查看当前系统中已有的文件系统信息:
mount
挂载 /etc/fstab 文件中所有已定义的设备文件:
mount-a
将光盘设备挂载到指定目录:
mount /dev/cdrom /Dir
强制以xfs文件系统挂载硬盘设备到指定目录:
mount-t xfs /dev/sdb /Dir
7.2 lspci 命令 – 显示当前设备 PCI 总线设备信息
7.2.1 含义
lspci 命令来自英文词组 list PCI 的缩写,其功能是用于显示当前设备 PCI 总线设备信息。
7.2.2 语法格式
lspci [参数] [设备名]
7.2.3 常用参数
参数
含义
-b
使用以总线为中心的视图
-d
仅显示指定厂商和设备信息
-i
设置 PCI 编号列表文件
-m
以机器可读方式显示 PCI 设备信息
-M
使用总线映射模式
-n
以数字方式显示 PCI 设备信息
-nn
将 PCI 厂商和设备代码显示为数字和名称形式
-q
使用 DNS 查询中央 PCI ID 数据库
-p
设置包含 PCI 总线信息的目录
-s
仅显示指定总线插槽的设备和功能块信息
-t
使用树状结构显示 PCI 设备的层次关系
-v
显示执行过程详细信息
7.2.4 参考示例
显示当前主机的所有PCI总线设备信息:
lspci
以树状结构显示当前主机的所有 PCI 总线设备信息:
lspci -t
7.3 sensors 命令 – 检测服务器硬件信息
7.3.1 含义
sensors 命令用于检测服务器硬件信息,例如 CPU 电压与温度、主板、风扇转速等数据。
7.3.2 语法格式
sensors
7.3.3 常用参数
参数
含义
-A
不显示每个芯片的适配器信息
-c
指定配置文件
-F
显示华氏度温度
-H
显示帮助信息
-u
输出原始信息
-v
显示版本信息
7.3.4 参考示例
检查当前 CPU 处理器得电压和温度信息:
sensors
8. 备份压缩 常用命令
8.1 zip 命令 – 压缩文件
8.1.1 含义
zip 命令的功能是用于压缩文件,解压命令为 unzip。通过 zip 命令可以将文件打包成 .zip 格式的压缩包,里面会包含文件的名称、路径、创建时间、上次修改时间等等信息,与 tar 命令相似。
8.1.2 语法格式
zip 参数 目标文件.zip 源文件或目录名
8.1.3 常用参数
参数
含义
-A
自动解压缩文件
-b
设置暂存文件的目录
-c
添加注释信息到压缩文件
-d
更新压缩包内文件
-F
尝试修复损坏的压缩文件
-h
显示帮助信息
-i
仅压缩符合条件的文件
-k
使用MS-DOS兼容格式
-l
将“LF”替换成“LF+CR”字符
-L
显示版本信息
-m
压缩后删除源文件
-n
不压缩具有特定字符串的文件
-q
静默执行模式
-r
递归处理所有子文件
-S
包含系统和隐藏文件
-t
设置压缩时间为指定日期
-T
检查压缩文件是否正确无误
-v
显示执行过程详细信息
-V
保留VMS操作系统的文件属性
-w
在文件名称中加入版本编号
-X
不保留过多的文件属性信息
-y
直接保存符号链接,而不是对应文件
8.1.4 参考示例
将指定目录及其内全部文件都打包成 zip 格式压缩包文件:
zip-r File.zip /etc
将当前工作目录内所有以 .cfg 为后缀的文件打包:
zip-r File.zip *.cfg
更新压缩包文件中某个文件:
zip-dv File.zip File.cfg
8.2 unzip 命令 – 解压缩 zip 格式文件
8.2.1 含义
unzip 命令用于解压缩 zip 格式文件,虽然 Linux 系统中更多地使用 tar 命令进行对压缩包的管理操作,但有时也会收到 Windows 系统常用的 .zip 和 .rar 格式的压缩包文件,unzip 命令便派上了用场。直接使用 unzip 命令解压缩文件后,压缩包内原有的文件会被提取并输出保存到当前工作目录下。