Last Updated on 2021年7月4日 by かんりにん
LinuxサーバーへdailyでSRXのコンフィグをバックアップするべく、tftpサーバーを設定しようと思ったら
どうやらtftpらしきものがないので、sshでリモートコマンドを使ってコンフィグをとってくる方法に変更。
作業としては前回のつづきw
バッチ処理にするためsshの認証を端折りたいので、SRXのログインアカウントにLinuxサーバーのアカウントの公開鍵を登録する方法をメモ。
- 参考:お世話になっております!
- Login with SSH keys instead of passwords to Junos router
http://junoshints.wordpress.com/2011/07/15/login-with-ssh-keys-instead-of-passwords-to-junos-router/
- サイト内関連ページ
[Juniper]SRX220 コンフィグのバックアップメモ
設定例
- リモートサーバー
IPアドレス :192.168.100.2 ホスト名 :REMOTEHOST ユーザー名 :remoteuser
- SRX環境
IPアドレス :192.168.100.254 ホスト名 :host-A ユーザー名 :admin
リモートサーバーにあるremoteuserの公開鍵をhost-Aのadminアカウントのプロファイルに登録
remoteuserの公開鍵はhost-A側からSCPで取得する。
設定手順
1)SRXへsshアクセス
$ ssh admin@192.168.100.254 admin@192.168.100.254's password: --- JUNOS 12.1X44-D25.5 built 2013-10-24 20:29:21 UTC {primary:node0} admin@host-A>
2)コンフィグモードへ切り替え
admin@host-A> configure warning: Clustering enabled; using private edit warning: uncommitted changes will be discarded on exit Entering configuration mode {primary:node0}[edit] admin@host-A#
上記の例では、rootでないのでログイン時のモードはオペレーションモードになっている。
rootでログインする場合は、CLIモードになっているので
オペレーションモード→コンフィグモードへの切り替えが必要。
3)sshの設定
sshの環境設定のため" set system services ssh"を実行。
admin@host-A# set system services ssh
4)ログインユーザーを指定し、公開鍵認証でアクセスしたいサーバーの公開鍵をscpでとってくる
admin@host-A# set system login user admin class super-user authentication load-key-file scp://remoteuser@192.168.100.2:/home/remoteuser/.ssh/id_dsa.pub remoteuser@192.168.100.2's password: id_dsa.pub 100% 606 0.6KB/s 00:00 {primary:node0}[edit] admin@host-A#
5)設定を適用する
admin@host-A# commit node0: configuration check succeeds node1: commit complete node0: commit complete {primary:node0}[edit]
6)動作確認
リモートホスト(192.168.100.2/REMOTEHOST)のremoteuserアカウントから
sshアクセスをテストし、パスワード入力不要でログインできることを確認。
$ ssh admin@192.168.100.254 --- JUNOS 12.1X44-D25.5 built 2013-10-24 20:29:21 UTC {primary:node0} admin@host-A>
→上記のとおり成功すればOK。