我正在家里运行 Ubuntu 14.04 的服务器。我的机器上有两个用户,例如user1
和user2
,每个用户都能够通过 ssh 进入该盒子。虽然user1
登录速度非常快,但user2
登录大约需要 20 秒。无论哪个用户从任何特定计算机登录,都会发生相同的行为。
登录user2
显示ssh -v
主暂停发生在此消息之后:
debug1: Sending environment.
.bashrc
两个用户的文件是相同的。(diff
它们上的 A 不产生输出。)和.profile
的文件也是如此。user1
user2
在服务器上,有一行/etc/ssh/sshd_config
以AllowUsers user1 user2
。UseDNS no
里面已经有同一个文件了。 (我只是提到这一点,因为我在搜索解决方案时发现的大多数页面都提到添加该行。)
这个问题大约一周前才开始;在我运行这台机器的前几年里,我没有遇到过这样的问题。
一时兴起,我创建了一个新用户 ,user3
通过适当的编辑为该用户提供了 ssh 访问权限sshd_config
,并且新用户的登录速度很快。所以这似乎确实与user2
配置方式有关。但什么?
我应该在哪里查找登录延迟的根本原因user2
?
编辑:以下是登录tail -f /var/log/auth.log
时的结果:user2
Jun 21 11:27:10 topo sshd[18386]: Connection from re.mo.te.ip port XXXXX on se.rv.er.ip port XX
Jun 21 11:27:21 topo sshd[18386]: Accepted password for user2 from re.mo.te.ip port XXXXX ssh2
Jun 21 11:27:21 topo sshd[18386]: pam_unix(sshd:session): session opened for user user2 by (uid=0)
Jun 21 11:27:21 topo systemd-logind[3347]: New session 25 of user user2.
Jun 21 11:28:03 topo sshd[18386]: User child is on pid XXXXX
Jun 21 11:28:03 topo sshd[18455]: Starting session: shell on pts/6 for user2 from re.mo.te.ip port XXXXX
请注意时间戳。延迟发生在此处的最后一条消息之后。user2
最终登录后,auth.log 中不会出现任何消息。
strace -f -p <sshd pid> -o out.tx -tt
编辑:以下是存在延迟的一些结果。
22733 12:59:10.414388 open("/usr/lib/python2.7/dist-packages/twisted/python/compat.x86_64-linux-gnu.so", O_RDONLY) = -1 ENOENT (No such file or directory)
22733 12:59:10.840303 open("/usr/lib/python2.7/dist-packages/twisted/python/compat.so", O_RDONLY) = -1 ENOENT (No such file or directory)
22733 12:59:11.264716 open("/usr/lib/python2.7/dist-packages/twisted/python/compatmodule.so", O_RDONLY) = -1 ENOENT (No such file or directory)
22733 12:59:11.717471 open("/usr/lib/python2.7/dist-packages/twisted/python/compat.py", O_RDONLY) = 4
22733 12:59:12.660275 fstat(4, {st_mode=S_IFREG|0644, st_size=11146, ...}) = 0
...
22733 12:59:12.661502 open("/usr/lib/python2.7/dist-packages/twisted/python/__future__.x86_64-linux-gnu.so", O_RDONLY) = -1 ENOENT (No such file or directory)
22733 12:59:13.212844 open("/usr/lib/python2.7/dist-packages/twisted/python/__future__.so", O_RDONLY) = -1 ENOENT (No such file or directory)
...
22733 12:59:14.441963 open("/usr/bin/dis.py", O_RDONLY) = -1 ENOENT (No such file or directory)
22733 12:59:14.900322 open("/usr/bin/dis.pyc", O_RDONLY) = -1 ENOENT (No such file or directory)
22733 12:59:15.401750 stat("/usr/lib/python2.7/dis", 0x7ffcb599ddd0) = -1 ENOENT (No such file or directory)
...
22733 12:59:17.315288 open("/usr/lib/python2.7/dist-packages/twisted/internet/termios.so", O_RDONLY) = -1 ENOENT (No such file or directory)
22733 12:59:17.967173 open("/usr/lib/python2.7/dist-packages/twisted/internet/termiosmodule.so", O_RDONLY) = -1 ENOENT (No such file or directory)
22733 12:59:18.511526 open("/usr/lib/python2.7/dist-packages/twisted/internet/termios.py", O_RDONLY) = -1 ENOENT (No such file or directory)
...
22733 12:59:25.993287 open("/usr/lib/python2.7/dist-packages/landscape/monitor/time.x86_64-linux-gnu.so", O_RDONLY) = -1 ENOENT (No such file or directory)
22733 12:59:26.612018 open("/usr/lib/python2.7/dist-packages/landscape/monitor/time.so", O_RDONLY) = -1 ENOENT (No such file or directory)
...
22733 12:59:29.688166 open("/proc/37/stat", O_RDONLY) = 9
22733 12:59:30.239695 fstat(9, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
...
22733 12:59:30.240450 open("/proc/uptime", O_RDONLY) = 10
22733 12:59:31.634404 fstat(10, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
...
22733 12:59:34.287758 open("/proc/557/stat", O_RDONLY) = 9
22733 12:59:34.851662 fstat(9, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
...
22758 12:59:39.500397 open(".", O_RDONLY) = 3
22758 12:59:40.377193 fchdir(3) = 0
22758 12:59:40.377312 newfstatat(AT_FDCWD, "/var/lib/apt//lists/", {st_mode=S_IFDIR|0755, st_size=12288, ...}, AT_SYMLINK_NOFOLLOW) = 0
22758 12:59:40.377378 open(".", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = 4
22758 12:59:40.878676 fchdir(4) = 0
...
22759 12:59:41.680427 open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
22759 12:59:42.249796 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P \2\0\0\0\0\0"..., 832) = 832
...
22759 12:59:46.019309 open("/etc/lsb-release", O_RDONLY|O_CLOEXEC) = 64
22759 12:59:46.948115 fstat(64, {st_mode=S_IFREG|0644, st_size=105, ...}) = 0
...
22786 12:59:50.251281 open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
22786 12:59:50.970074 fcntl(1, F_GETFD) = 0
...
22785 12:59:53.338632 select(10, [3 4 6], [], NULL, NULL) = 1 (in [3])
22785 12:59:53.771002 rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
其中很多似乎与 python 库有关。然而,它们也会在user1
登录时加载,只是没有这 0.5 秒的暂停。