[C841M]sshの設定

○2017/7/26

●sshの設定
初期設定から

>en (enableの略)
#conf t (configure terminalの略)
(config)#username admin password password
(config)#ip domain-name cisco123
(config)#line vty 0 4
(config-line)#login local
(config-line)#transport input ssh
 ←telnetの設定時同様、これ忘れずに
(config-line)#exit
(config)#crypto key generate rsa
% Please define a hostname other than Router.
 ←ホスト名を決めておかないといけないのな。
(config)#hostname myRouter
(config)#crypto key generate rsa
The name for the keys will be: myRouter.cisco123
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]:(Enter押す)
% Generating 512 bit RSA keys, keys will be non-exportable...
[OK] (elapsed time was 1 seconds)
(config)#ip ssh version 1
(config)#ip ssh time-out 60
(config)#ip ssh authentication-retries 2
(config)#exit

コマンドの省略形を探るのが面倒になってきたので、やめました。
どうせ、Tabキー押せば出てくるので。

では、teratermからssh接続。
→ホストに接続できません(NG)

そうだね。VLANの設定してないね。

#conf t
(config)#int vlan 1 (interfaceの略)
(config-if)#ip address 192.168.1.1 255.255.255.0
(config-if)#exit
(config)#exit

改めて、teratermからssh接続。
→プロトコルバージョンが一致しません(サーバ:1.5, クライアント:2)

teratermで接続時の、「SSHバージョン」を「SSH1」にして接続
→OK
(設定したユーザー名とパスワード(admin, password)を入力 →
セキュリティ警告の画面は「SHA256」と「このホストを記憶する」にチェック入れて「続行」)

で、ssh接続した側でenableモードにログインしようとすると、

>en
% No password set

って出てきてログインできない。
telnet設定のときもそういう注意書きがあったね。

シリアルコンソール側に戻って、

#conf t
(config)#en p password (enable passwordの略)
(config)#exit

改めて、teratermで接続時の、「SSHバージョン」を「SSH1」にして接続
→OK

enableモード

>en
(パスワード入力)
#

→OK

これは・・・
シリアルコンソールとsshの両側からenableモードで操作できるのは、
問題ないのかね?

ひとまず設定完了。
試しに、sshのバージョンを2にしてやってみる。

#conf t
(config)#ip ssh version 2
Please create RSA keys to enable SSH (and of atleast 768 bits for SSH v2).
 ←なんか、keyを改めて作らなきゃダメなん?
(config)#crypto key generate rsa
% You already have RSA keys defined named myRouter.cisco123.
% Do you really want to replace them? [yes/no]: (yesを入力)
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]:(768を入力:↑↑の警告に従って)
% Generating 768 bit RSA keys, keys will be non-exportable...
[OK] (elapsed time was 0 seconds)

なんか、ログでさ、
%SSH-5-ENABLED: SSH 1.99 has been enabled
って出てきたんだけど、
SSHのバージョンって、2じゃねーの?

一応、やってみるか。
teratermで接続時の、「SSHバージョン」を「SSH2」にして接続
→NG (接続操作中に途中で切断される)

あれかなぁ?
バージョン1で接続したときに、「このホストを記憶する」にしたからかなぁ?

泥沼編へ続く

必要なコマンドをもう一度整理(sshのversionは1で設定する)

>en
#conf t
(config)#en p password
(config)#username admin password password
(config)#ip domain-name cisco123
(config)#line vty 0 4
(config-line)#login local
(config-line)#transport input ssh
(config-line)#exit
(config)#hostname myRouter
(config)#crypto key generate rsa (キーの長さはデフォルトの512のまま[Enter]※)
(config)#ip ssh version 1
(config)#ip ssh time-out 60
(config)#ip ssh authentication-retries 2
(config)#int vlan 1
(config-if)#ip address 192.168.1.1 255.255.255.0
(config-if)#exit
(config)#exit

※RSAキーの長さについて
今回はデフォルトの512で作成したが、
実際は1024や2048などで作成するのが一般的っぽい。
参考サイト:
http://www.infraexpert.com/study/ciscorouter7.html
http://beginners-network.com/cisco-catalyst-command/crypto-key-generate-rsa.html

ちなみに、teratermでRSA鍵を作成するときのデフォルトは2048

コメントを残す

メールアドレスが公開されることはありません。