解决 ssh 登录到ubuntu server 慢的问题
最近在服务器上使用ubuntu系统,服务器上开启sshd服务,在客户端处使用ssh登录到服务器的时候出现卡顿的现象。
在网上搜索了解决方案,主要是:
1. 修改服务器的 /etc/ssh/sshd_config
添加 UseDNS no
2. 修改服务器的 /etc/ssh/ssh_config
添加 GSSAPIAuthentication no
然后重新启动ssh 服务, /etc/init.d/ssh restart
尝试了以上方法发现都不起作用,于是使用 ssh -v root@192.168.1.2 进行ssh登录过程跟踪,发现如下记录:
debug1: Authentications that can continue: publickey,password debug1: Next authentication method: publickey debug1: Trying private key: /home/jason/.ssh/id_rsa debug1: Trying private key: /home/jason/.ssh/id_dsa debug1: Trying private key: /home/jason/.ssh/id_ecdsa debug1: Trying private key: /home/jason/.ssh/id_ed25519 debug1: Next authentication method: password root@192.168.1.2's password: debug1: Authentication succeeded (password). Authenticated to 192.168.1.2 ([192.168.1.2]:22). debug1: channel 0: new [client-session] debug1: Requesting no-more-sessions@openssh.com debug1: Entering interactive session. debug1: Sending environment. debug1: Sending env LC_PAPER = zh_CN.UTF-8 debug1: Sending env LC_ADDRESS = zh_CN.UTF-8 debug1: Sending env LC_MONETARY = zh_CN.UTF-8 debug1: Sending env LC_NUMERIC = zh_CN.UTF-8 debug1: Sending env LC_TELEPHONE = zh_CN.UTF-8 debug1: Sending env LC_IDENTIFICATION = zh_CN.UTF-8 debug1: Sending env LANG = en_US.UTF-8 debug1: Sending env LC_MEASUREMENT = zh_CN.UTF-8 debug1: Sending env LC_TIME = zh_CN.UTF-8 debug1: Sending env LC_NAME = zh_CN.UTF-8
发现在 debug1: Entering interactive session. 的地方会卡顿几十秒。
登录成功以后,系统给出登陆后的信息:
Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.0.35-2508-g54750ff armv7l) * Documentation: https://help.ubuntu.com/ 495 packages can be updated. 296 updates are security updates. New release '12.10' available. Run 'do-release-upgrade' to upgrade to it. Last login: Thu Jan 1 01:05:10 1970 from 192.168.1.106
上面的内容在其它版本中为/etc/motd
中的内容,但ubuntu是动态生成该内容,生成脚本在/etc/update-motd.d
目录下,查看脚本可以是联网检测系统更新等情况。
修改/etc/pam.d/sshd
和/etc/pam.d/login
文件中的有pam_motd.so的行注释掉
#session optional pam_motd.so motd=/run/motd.dynamic noupdate #session optional pam_motd.so # [1]
再次ssh,这次没有了上面的update等信息了,但ssh也不卡顿了。
参考:http://yaxin-cn.github.io/Linux/solve-ssh-slow-to-ubuntu.html