ふと、Ubuntu 14.04のホストからCiscoルータ(Cisco1812J)へログインしようとした際に、ログインできなかった。
$ ssh xxx.xxx.xxx.xxx
Connection closed by xxx.xxx.xxx.xxx
そのときに、1812J側で出たメッセージは以下。
1017854: May 6 15:32:48.673 JST: SSH2 1: Invalid modulus length
試しに、「debug ip ssh」してみると、
1017830: May 6 15:32:48.637 JST: SSH1: starting SSH control process
1017831: May 6 15:32:48.637 JST: SSH1: sent protocol version id SSH-2.0-Cisco-1.25
1017832: May 6 15:32:48.641 JST: SSH1: protocol version id is - SSH-2.0-OpenSSH_6.6p1 Ubuntu-2ubuntu1
1017833: May 6 15:32:48.641 JST: SSH2 1: send:packet of length 344 (length also includes padlen of 5)
1017834: May 6 15:32:48.641 JST: SSH2 1: SSH2_MSG_KEXINIT sent
1017835: May 6 15:32:48.657 JST: SSH2 1: ssh_receive: 536 bytes received
1017836: May 6 15:32:48.657 JST: SSH2 1: input: total packet length of 1792 bytes
1017837: May 6 15:32:48.657 JST: SSH2 1: partial packet length(block size)8 bytes,needed 1784 bytes,
maclen 0
1017838: May 6 15:32:48.657 JST: SSH2 1: ssh_receive: 536 bytes received
1017839: May 6 15:32:48.657 JST: SSH2 1: partial packet length(block size)8 bytes,needed 1784 bytes,
maclen 0
1017840: May 6 15:32:48.657 JST: SSH2 1: ssh_receive: 536 bytes received
1017841: May 6 15:32:48.657 JST: SSH2 1: partial packet length(block size)8 bytes,needed 1784 bytes,
maclen 0
1017842: May 6 15:32:48.657 JST: SSH2 1: ssh_receive: 184 bytes received
1017843: May 6 15:32:48.657 JST: SSH2 1: partial packet length(block size)8 bytes,needed 1784 bytes,
maclen 0
1017844: May 6 15:32:48.657 JST: SSH2 1: input: padlength 10 bytes
1017845: May 6 15:32:48.661 JST: SSH2 1: SSH2_MSG_KEXINIT received
1017846: May 6 15:32:48.661 JST: SSH2:kex: client->server enc:aes128-cbc mac:hmac-md5
1017847: May 6 15:32:48.661 JST: SSH2:kex: server->client enc:aes128-cbc mac:hmac-md5
1017848: May 6 15:32:48.673 JST: SSH2 1: ssh_receive: 24 bytes received
1017849: May 6 15:32:48.673 JST: SSH2 1: input: total packet length of 24 bytes
1017850: May 6 15:32:48.673 JST: SSH2 1: partial packet length(block size)8 bytes,needed 16 bytes,
maclen 0
1017851: May 6 15:32:48.673 JST: SSH2 1: input: padlength 6 bytes
1017852: May 6 15:32:48.673 JST: SSH2 1: SSH2_MSG_KEX_DH_GEX_REQUEST received
1017853: May 6 15:32:48.673 JST: SSH2 1: Range sent by client is - 1024 < 3072 < 8192
1017854: May 6 15:32:48.673 JST: SSH2 1: Invalid modulus length
1017855: May 6 15:32:48.773 JST: SSH1: Session disconnected - error 0x00
んー、何が起こってるかわからない…
「SSH Invalid modulus length」でググってみて、見つけたこのページ。
Cisco機器側に以下のコマンドを投入しろとのこと。
cisco886va(config)#ip ssh dh min size 4096
上記を入れると確かにログインできるようになった。
でも、今までルータ側の設定を弄らなくてもログインできていたし、明らかにSSHクライアント側の問題だろうと思い、もうちょっとググってみる。
ググってみると、クライアント側で指定できる「KexAlgorithms」が関係ありそうであることがわかった。
そして見つけたRedHatのBugzilla。
最近のSSHクライアントを使って接続した際に起こる問題で、クライアント側から接続時に送信されるネゴシエーションオプションが長すぎるために、サーバ側であるCisco機器がそのオプションを格納するためのバッファを格納できずにこの問題が起こるみたい。
ちなみに、SSHサーバ側はCiscoルータ/スイッチだけでなく、HPのiLO server management processorとかでも起きている問題らしい。
というわけで、以下のコマンドで再度ログイン。
$ ssh -o KexAlgorithms=diffie-hellman-group14-sha1 xxx.xxx.xxx.xxx
Password:
Router>exit
入れたー!めでたしめでたし。
毎回「-o」オプションを指定するのは面倒くさいので、「.ssh/config」に以下のようなエントリを追加して終わり。
Host hoge
HostName xxx.xxx.xxx.xxx
KexAlgorithms diffie-hellman-group14-sha1
これで、「ssh hoge」でオプションを指定せずともログインできる。