タイトルそのまんま。CentOS7で最近構築したgateサーバからLAN内のマシンにSSHするとき、やたら遅い。ログインまで数秒を要する。ただし初回のみ。二回目以降はとてもはやい。
デバッグしてみる
ssh -vと、vオプションを指定してやればsshがデバッグモードで動く。
1 2 3 4 5 6 |
# ssh -v www.rite.jp OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013 debug1: Reading configuration data /root/.ssh/config debug1: /root/.ssh/config line 1: Applying options for * debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 56: Applying options for * ←ここで数秒止まる |
/etc/ssh/ssh_configの読み込みに時間がかかっているようだ。より具体的には56行目。ということで/etc/ssh/ssh_configの56行目付近をみてみる。
1 2 3 4 5 6 7 8 |
52 # Uncomment this if you want to use .local domain 53 # Host *.local 54 # CheckHostIP no 55 56 Host * 57 GSSAPIAuthentication yes 58 # If this option is set to yes then remote X11 clients will have full access 59 # to the original X11 display. As virtually no X11 client supports the untrusted |
GSSAPIAuthenticationが有効になっているのが原因のようだ。
GSSAPIAuthentication (GSSAPI 認証)
GSSAPI ベースの認証をおこなうかどうかを指定します。デフォルトの値は”no”です。
Generic Security Service APIといって、APIを使ったセキュアなログインをする設定のようだ。そのネゴシエーションがやたら遅い。
対応
もともとAPIを使ったログインなんてしないし、デフォルトでnoならnoにしてしまえば良い(使っているサーバのバージョンではなぜかデフォルトyesになっていた)。
・・・しかしnoにしてもまだ遅い。
Host *が悪いようなので、コメントアウトすることにした。
1 |
vi /etc/ssh/ssh_config |
1 2 |
56 #Host * 57 # GSSAPIAuthentication yes |
1 |
systemctl restart sshd |
で、結果はというと…。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# ssh -v www.rite.jp OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Connecting to www [192.168.4.7] port 22. debug1: Connection established. debug1: permanently_set_uid: 0/0 debug1: identity file /root/.ssh/id_rsa type -1 debug1: identity file /root/.ssh/id_rsa-cert type -1 debug1: identity file /root/.ssh/id_dsa type -1 debug1: identity file /root/.ssh/id_dsa-cert type -1 debug1: identity file /root/.ssh/id_ecdsa type -1 debug1: identity file /root/.ssh/id_ecdsa-cert type -1 debug1: identity file /root/.ssh/id_ed25519 type -1 debug1: identity file /root/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.6.1 debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1 debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none debug1: kex: curve25519-sha256@libssh.org need=16 dh_need=16 debug1: kex: curve25519-sha256@libssh.org need=16 dh_need=16 debug1: sending SSH2_MSG_KEX_ECDH_INIT debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ECDSA 12:a8:d1:e3:b5:1f:f0:c6:59:b5:39:4b:a5:c6:41:fa debug1: Host 'dns' is known and matches the ECDSA host key. debug1: Found key in /root/.ssh/known_hosts:19 debug1: ssh_ecdsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: Roaming not allowed by server debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: Next authentication method: publickey debug1: Trying private key: /root/.ssh/id_rsa debug1: key_parse_private2: missing begin marker debug1: read PEM private key done: type RSA debug1: Authentication succeeded (publickey). Authenticated to www ([192.168.4.7]:22). debug1: channel 0: new [client-session] debug1: Requesting no-more-sessions@openssh.com debug1: Entering interactive session. debug1: Sending environment. debug1: Sending env LANG = ja_JP.UTF-8 Last login: Thu Oct 12 12:58:53 2017 from gate.rite.jp |
わずか0.3秒くらいでログイン完了。めっちゃ早い。
GSSAPIAuthenticationは絶対にコメントアウトしておこう。
10/19 追記 まだ遅かった
一旦は解決したはずが、まだまだ遅い。気づかなかったけれど初回アクセスのみ異常に遅い。
どうもIPv6での通信を試みているフシがある。ということで接続範囲をIPv4に限定した。
1 2 3 4 5 6 |
###以下の設定を入れる vi /etc/ssh/ssh_config AddressFamily inet ### 再起動 systemctl restart sshd |
うーん…。
速い!速すぎる!今度こそ解決した。