在 CentOS 上测试 SSH 连通性,常见有几种方式,按使用场景从简单到深入说明:
ssh 用户名@目标IP
例如:
ssh root@192.168.1.100
Are you sure you want to continue connecting (yes/no)?
输入 yes 即可ssh -p 端口号 用户名@目标IP
例如:
ssh -p 2222 root@192.168.1.100
ssh -o ConnectTimeout=5 用户名@目标IP exit
或:
ssh -q -o BatchMode=yes 用户名@目标IP exit
telnettelnet 目标IP 22
看到类似:
SSH-2.0-OpenSSH_7.4
说明端口通
ncnc -zv 目标IP 22
nmapnmap -p 22 目标IP
systemctl status sshd
或
ss -lntp | grep :22
本地连接测试:
ssh localhost
systemctl start sshd
systemctl enable sshd
firewall-cmd --add-service=ssh --permanent
firewall-cmd --reload
如果你愿意,可以告诉我:
我可以帮你精准定位问题。