一個使用者的 openSSH 登入速度較慢,但其他使用者則不然

一個使用者的 openSSH 登入速度較慢,但其他使用者則不然

我正在家裡運行 Ubuntu 14.04 的伺服器。我的機器上有兩個用戶,例如user1user2,每個用戶都能夠透過 ssh 進入該盒子。雖然user1登入速度非常快,但user2登入大約需要 20 秒。

登入user2顯示ssh -v主暫停發生在此訊息之後:

debug1: Sending environment.

.bashrc兩個使用者的文件是相同的。(diff它們上的 A 不產生輸出。)和.profile的檔案也是如此。user1user2

在伺服器上,有一行/etc/ssh/sshd_configAllowUsers user1 user2UseDNS 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 秒的暫停。

相關內容