「OpenSSH」- 常见问题整理

常见问题的常规排查方法

当 OpenSSH 服务无法连接时,或者行为与预期不符时,有以下两种方法(通用且极其有效的方法):
1)执行 ssh 时,添加-v 选项(或者更多-v 选项),以进入调试模式;
2)手动启动 sshd 服务,添加-d 选项(或者更多-d 选型),以进入调试模式;

这么多年,它已经非常成熟,我们遇到的问题通常可以通过日志提示进行解决;

Too many authentication failures

How to Fix “SSH Too Many Authentication Failures” Error

# ssh -o IdentitiesOnly=yes "<hostname>"

OpenSSH Slow: Hanging at SSH2_MSG_SERVICE_ACCEPT received

[FIXED] OpenSSH Slow: Hanging at SSH2_MSG_SERVICE_ACCEPT received

问题描述:
在用户密码输入提示出现之前,总要等待一段时间,在一会之后密码提示符才会才会显示出来;

问题原因:
修改 SSHD 的LogLevel DEBUG3后,日志中显示 SSHD 服务尝试解析客户端的 IP 地址;

Could not open a connection to your authentication agent.

git – Could not open a connection to your authentication agent – Stack Overflow

当执行 ssh-add 命令时,产生如下错误:

# ssh-add /path/to/id_ras
Could not open a connection to your authentication agent.

问题原因

在环境变量中,相关参数未设置,导致程序无法找到 ssh-agent 服务。需要设置的变量如下:

# ssh-agent -s
SSH_AUTH_SOCK=/tmp/ssh-SUEIyA5guxOn/agent.3917; export SSH_AUTH_SOCK;
SSH_AGENT_PID=3918; export SSH_AGENT_PID;
echo Agent pid 3918;

解决方案

# source <(ssh-agent -s) >/dev/null

UseDNS – 指定 sshd(8)是否应查找远程 SSH 客户端主机名,并检查”通过远程客户端 IP 地址的解析到的主机名“是否映射回完全相同的 IP 地址。如果该选项设置为no,则只能在~/.ssh/authorized_keysfrom指令和sshd_configMatch Host指令中使用 IP 地址,而不能使用主机名;

解决办法:
修改服务端,将/etc/ssh/sshd_config中的UseDNS设置为no,然后重启服务;

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

linux – Temporarily ignore my `~/.ssh/known_hosts` file? – Server Fault
verification – ssh remote host identification has changed – Stack Overflow

我们通过选项来忽略该提示,而不是修改 known_hosts 文件:

ssh -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null user@host

Please login as the user “centos” rather than the user “root”.

Unable to migrate to Plesk for Linux from AWS: please login as the user “centos” rather than the user “root”

解决方案:检查 ~/.ssh/authorized_keys 文件,清除 Key 以外的内容;