NW機器も公開鍵認証でSSH

NW機器もそろそろSSHでアクセスするときは公開鍵認証でやるべきかと思い, 主に触るであろうNW機器の設定をまとめた。

– 鍵準備

SSHで必要となる公開鍵を準備する。

$ ssh-keygen -t rsa -C user01 -f ./rsa_id
$ ls rsa*
rsa_id.pub #公開鍵
rsa_id #秘密鍵

– Cisco IOS

参考: SSH using public key authentication to IOS and big outputs.

1. SSH設定

# conf t
(config)# ip ssh version 2
(config)# line vty 0 4
(config-line)# login local
(config-line)# transport input ssh
(config-line)# hostname R1
(config)# ip domain name test.local
(config)# crypto key gen rsa

2. ユーザと公開鍵紐付け

(config)# ip ssh pubkey-chain
(conf-ssh-pubkey)# username cisco
(conf-ssh-pubkey-user)# key-string
(conf-ssh-pubkey-data)#
※ 最大で貼り付けられる文字数が256字ということで複数行に分けてペーストする。
(conf-ssh-pubkey-data)# exit
(conf-ssh-pubkey-user)# end
#

テスト

$ ssh -l cisco -i ./rsa.id 172.16.1.1
R1>


– VyOS

参考:Remote access

1. SSH設定

set service ssh port '22'

2. ユーザと公開鍵の紐付け認証設定

set system login user user1 authentication public-keys '鍵の識別子' key 'public key内の文字列のみ入力'  #ssh-rsa と ユーザは抜く

3. パスワード認証無効化

set service ssh disable-password-authentication

4. ホストバリデーション無効化(オプション)

set service ssh disable-host-validation

テスト

$ ssh -l user1 -i ./rsa_id 172.16.1.2
Welcome to VyOS

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login:
user1@vyos:~$

– Cisco ASA(9.x)

参考:Cisco ASA シリーズ 9.8 CLI コンフィギュレーション ガイド(一般的な操作)

1. SSH設定

ひとまずOutsideから全許可。

(config)# ssh 0.0.0.0 0.0.0.0 outside

2. 公開鍵のフォーマット変更

公開鍵をRFC4716形式で出力。

$ ssh-keygen  -e -m rfc4716 -f ./rsa_id.pub  # この出力結果を控えておく

3. ユーザと公開鍵の紐付け

(config)# aaa authentication ssh console LOCAL
(config)# username user1 attributes
(config-username)# service-type admin
(config-username) ssh authentication pkf

Enter an SSH public key formatted file.
End with the word "quit" on a line by itself:
### 2で変換したPublic Keyを貼り付ける ###
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "2048-bit RSA, converted by ubuntu@HOST from OpenSSH"
~~~
---- END SSH2 PUBLIC KEY ----
quit

テスト

$ ssh -l user1 -i ./rsa_id 172.16.1.3
User user1 logged in to ASA
Logins over the last 1 days: 2. Last login: 06:54:33 UTC Dec 8 2018 from 192.168.1.10
Failed logins since the last login: 0.
Type help or '?' for a list of available commands.
ASA>

– Cumulus linux

0. NCLU(Network Command Line Utility)インストール

参考:Network Command Line Utility – NCLU
※ ここは省略

1. LinuxのSSH公開鍵認証設定

ホームの.ssh配下のauthorized_keysに公開鍵を登録。

テスト

$ ssh -l cumulus -i ./rsa_id 172.16.1.4

Welcome to Cumulus VX (TM)

Cumulus VX (TM) is a community supported virtual appliance designed for
experiencing, testing and prototyping Cumulus Networks' latest technology.
For any questions or technical support, visit our community site at:
http://community.cumulusnetworks.com

The registered trademark Linux (R) is used pursuant to a sublicense from LMI,
the exclusive licensee of Linus Torvalds, owner of the mark on a world-wide
basis.
Last login: Sat Dec 8 04:45:53 2018 from 192.168.1.10
cumulus@cumulus:~$

– JUNOS

参考:authentication (Login)

1. SSH設定

 set system services ssh protocol-version v2

2. ユーザと公開鍵紐付け

set system login user admin authentication ssh-rsa "ssh-rsa 省略 user01"

テスト

$ ssh -l admin -i ./user2_rsa 172.16.1.5
Last login: Thu Dec 6 18:07:53 2018 from 192.168.1.10
--- JUNOS 15.1X49-D140.2 built 2018-05-25 18:23:50 UTC
admin>