Linux ssh命令:安全的遠程連接服務器
ssh命令的功能是用于安全的遠程連接服務器主機系統,作為openssh套件中的客戶端連接工具,ssh命令可以讓我們輕松的基于ssh加密協議進行遠程主機訪問,從而實現對遠程服務器的管理工作。
語法格式: ssh [參數] 遠程主機
常用參數:
-1 強制使用ssh協議版本1
-2 強制使用ssh協議版本2
-4 強制使用IPv4地址
-6 強制使用IPv6地址
-A 開啟認證代理連接轉發功能
-a 關閉認證代理連接轉發功能
-b<IP地址> 使用本機指定的地址作為對位連接的源IP地址
-C 請求壓縮所有數據
-F<配置文件> 指定ssh指令的配置文件,默認的配置文件為“/etc/ssh/ssh_config”
-f 后臺執行ssh指令
-g 允許遠程主機連接本機的轉發端口
-i<身份文件> 指定身份文件(即私鑰文件)
-l<登錄名> 指定連接遠程服務器的登錄用戶名
-N 不執行遠程指令
-o<選項> 指定配置選項
-p<端口> 指定遠程服務器上的端口
-q 靜默模式,所有的警告和診斷信息被禁止輸出
-X 開啟X11轉發功能
-x 關閉X11轉發功能
-y 開啟信任X11轉發功能
參考實例
基于ssh協議,遠程訪問服務器主機系統:
[root@linuxcool ~]# ssh 192.168.10.10
The authenticity of host '192.168.10.10 (192.168.10.10)' can't be established.
ECDSA key fingerprint is SHA256:ZEjdfRjQV8pVVfu0TSYvDP5UvOHuuogMQSDUgLPG3Kc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.10' (ECDSA) to the list of known hosts.
root@192.168.10.10's password: 此處輸入遠程服務器管理員密碼
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Tue Dec 14 08:49:08 2022
[root@linuxprobe ~]#
使用指定的用戶身份登錄遠程服務器主機系統:
[root@linuxcool ~]# ssh -l linuxprobe 192.168.10.10
linuxprobe@192.168.10.10's password: 此處輸入指定用戶的密碼
Activate the web console with: systemctl enable --now cockpit.socket
[linuxprobe@linuxprobe ~]$
登錄遠程服務器主機系統后執行一條命令:
[root@linuxcool ~]# ssh 192.168.10.10 "free -m"
root@192.168.10.10's password: 此處輸入遠程服務器管理員密碼
total used free shared buff/cache available
Mem: 1966 1359 76 21 530 407
Swap: 2047 9 2038
強制使用v1版本的ssh加密協議連接遠程服務器主機:
[root@linuxcool ~]# ssh -1 192.168.10.10