今まではキーペアを作る→公開鍵をscpで送る or catで中身コピー→authorized_keysに張り付けとかをやっていたけど、簡単にやってくれるコマンドがあった。
最近知った。便利だね。
 

#キーペア作成
[root@RAIDER modules]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): ←空Enter
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): ←空Enter
Enter same passphrase again: ←空Enter
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:uKcCk/BL77rWURFlN53cL9ub6yYuF3DtMR8yAFLE1zk root@RAIDER
The key's randomart image is:
+---[RSA 2048]----+
|      .+*++o.o.  |
|      ...o ++E.  |
|       .  . . o. |
|.     ..   . +.=.|
| o . .. S   o ++=|
|  * .  .     ...o|
| . * .. .     . o|
|  o +  o   . o + |
| .o+...     +.+o.|
+----[SHA256]-----+

#PublicKeyの内容を相手先のauthorized_keysに書き込む
[root@RAIDER modules]# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.0.45
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.0.45 (192.168.0.45)' can't be established.
ECDSA key fingerprint is SHA256:KrJXKdVuhtO0CX+cJ3TXpGIvoKaup1VmHMYAg7PDkmg.
ECDSA key fingerprint is MD5:e6:74:ab:2f:aa:9e:fe:ae:86:f1:62:51:c1:f6:5e:da.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.0.45's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.0.45'"
and check to make sure that only the key(s) you wanted were added.

#ログインしてみる
[root@RAIDER modules]# ssh 192.168.0.45
Last login: Fri May  4 04:30:30 2018 from 192.168.0.2
[root@HYPERION ~]#

<スポンサーリンク>

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)