2017
Dec
30

SSH 连线到某些机器,有时候会等超过 5 秒,有一个原因就是 UseDNS 这个设定,当 UseDNS = yes , SSH 伺服器就会做一次 reverse DNS , reverse DNS 就是将 IP 转成 hostname , SSHD Server 转换 iphostname 后会检查 client 的 ip 与 hostname 是否一致 ,唯一的用途是做 hostname-based host authentication 登入机制,不过这个机制一点都不安全,也几乎没有机器需要这个功能,所以我们可以直接取消这个设定。

当 SSH Server 没有做 Reverse DNS , 登入的速度就会快很多了

官方对 UseDNS 的说明如下:

Specifies whether sshd(8) should look up the remote host name and check that the resolved host name for the remote IP address maps back to the very same IP address. The default is ''yes''.

修改 SSH daemon 设定

  • Mac 系统的设定档: /etc/sshd_config
  • Linux 系统的设定档: /etc/ssh/sshd_config

你只要在 sshd_config 加上这个设定,在重启 SSHD server 即可。

UseDNS no

Mac 重启 SSHD 方式

  • sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist && sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

Linux 重启 SSHD 方式有好多种:

  • sudo service sshd restart
  • sudo systemctl restart sshd
  • sudo /etc/init.d/ssh restart

停用 GSSAPIAuthentication

GSSAPIAuthentication 全名是 Generic Security Services API,这个功能平常也是用不到,所以可以直接停用。

/etc/ssh/sshd_config
  1. UseDNS no
  2. GSSAPIAuthentication no

GSSAPIAuthentication 也可以在 Client 端设定不要使用,你可以修改 ~/.ssh/config

~/.ssh/config
  1. GSSAPIAuthentication no
  2. GSSAPIDelegateCredentials yes

回應 (Leave a comment)