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