CISCOルーターへのSSH接続

SSHの設定

ネットワーク機器にはtelnetでアクセスする風習があるらしいが,
.ssh/configにかけなくて面倒なのでsshアクセスできるように設定する.

参考:

https://www.itbook.info/network/cisco13.htmlwww.itbook.info

www.infraexpert.com

ユーザー・パスワードの設定

admin/cisco でユーザー名・パスワードを設定する. privilege 15をつけることでログイン時に特権モードで入れる. password/secret はconfigの表示時に見れるかどうか.

Router> enable
Router# configure terminal
Router(config)# username admin (privilege 15) [password/secret] cisco

ドメイン名の設定

ssh サーバーをたてるにはドメイン名を設定しないといけないらしい

Router> enable
Router# configure terminal
Router(config)# ip domain-name xxxxxxxx

鍵生成

ssh で使用する鍵を生成する. ここでは 2048bit のRSA暗号化鍵を生成

Router> enable
Router# configure terminal
Router(config)# crypto key generate rsa
The name for the keys will be: Router.xxxxxxxx
Choose the size of the key modulus in the range of 360 to 4096 for your
  General Purpose Keys. Choosing a key modulus greater than 512 may take
  a few minutes.

How many bits in the modulus [512]: 2048
% Generating 2048 bit RSA keys, keys will be non-exportable...
[OK] (elapsed time was 1 seconds)

ssh version2 の設定

デフォルトでは SSH version 1.99 が設定されているが,
以下のコマンドで version 2 のみに設定し直す

Router(config)ip ssh version 2

ssh サーバーの設定

Router(config)# line vty 0 15
Router(config-line)# login local
Router(config-line)# transport input ssh
Router(config-line)# end

ssh 接続

クライアント側からルーターsshで接続する

ssh admin@xxx.xxx.xxx.xxx

パスワードを聞かれたらユーザー名と共に設定したパスワードを入れてログイン

ログインできない場合

ssh: connect to host xxx.xxx.xxx.xxx port 22: No route to host

のエラーは宛先IPアドレスが間違っているか,ポートが間違っている可能性があるので確認する

Unable to negotiate with xxx.xxx.xxx.xxx port 22: no matching cipher found. Their offer: aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc

上の場合はクライアント側で,aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc のどれかの暗号化方式をオプションとして以下のようにつけて再度繋いで見る

ssh -c aes128-cbc admin@xxx.xxx.xxx.xxx

もしくは,sshの設定をいじる.
Ubuntu 18.04の場合,/etc/ssh/ssh_configのCiphersの行のコメントアウトを外すとオプションをつけなくても良くなる

(.ssh/configにかけるように後者の方が良さそう?)

最後に

sshがささるまで2, 3秒かかるのは何故?こんなもんなのか?