ばっかじゃないの!

じゃみらー

sshでパスワードを要求されるまでが遅いとき

色々と調べてみたら,sshdがデフォルトでDNS逆引きをしているらしい.
つまり問題はsshの接続先の設定の問題.
解決方法はsshの接続先がUbuntuだったら
/etc/ssh/sshd_config に
UseDNS no
と書き加えて
sudo kill -HUP `cat /var/run/sshd.pid`
(再起動)して,sshで接続しなおす.
たぶん他のOSだとsshdの再起動コマンドがちゃんとあると思う.
僕のおもちゃにはなくて仕方なくkill -HUPした.


ちなみにすでに /etc/hosts にIP登録してます.
2回目以降の接続が高速になると思います*1
http://d.hatena.ne.jp/yuyarin/20090410/1239298235
の一番はじめの方法.

参考にしたサイトは以下
http://d.hatena.ne.jp/yuyarin/20090410/1239298235
http://q.hatena.ne.jp/1171081145
http://www.unixuser.org/~euske/doc/openssh/jman/sshd_config.html
http://open-groove.net/linux/sshd-restart/

蛇足ながら,解決前の状況を具体的にデバッグオプションをつけてログを見てみると,以下のようになっていた.

hage:~ hoge$ ssh -v negi-cal
#hageというクライアントからnegi-calというサーバにhogeというアカウントでアクセスしようとする.-v はデバッグオプション
OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /Users/hoge/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
#ここまで設定読み込み
debug1: Connecting to negi-cal [192.168.1.092] port 22.
debug1: Connection established.
#とりあえずnegi-calには到達できたらしい
debug1: identity file /Users/hoge/.ssh/id_rsa type -1
debug1: identity file /Users/hoge/.ssh/id_rsa-cert type -1
debug1: identity file /Users/hoge/.ssh/id_dsa type -1
debug1: identity file /Users/hoge/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.8p1 Debian-1ubuntu3
debug1: match: OpenSSH_5.8p1 Debian-1ubuntu3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'negi-cal' is known and matches the RSA host key.
debug1: Found key in /Users/hoge/.ssh/known_hosts:109
debug1: ssh_rsa_verify: signature correct
#negi-calに確かにhageであると認証されたみたい
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,password
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/hoge/.ssh/id_rsa
debug1: Trying private key: /Users/hoge/.ssh/id_dsa
debug1: Next authentication method: password
hoge@negi-cal's password: 
#ここでログインパスワード入力

*1:が下のサイトでは「個別対応なのであまり良い解決策ではないが,やむを得ない場合はこの方法」と言われちゃってます.しょぼんぬ.