LoginSignup
0
0

More than 3 years have passed since last update.

公開鍵を使ったSSH接続のやり方

Last updated at Posted at 2019-07-12

経緯

Ansibleを実行するためには、構築対象のマシンへ公開鍵でSSH接続する必要があるためと、 ssh-keygenとssh-copy-idコマンドを忘れそうだから備忘録を兼ねて。

鍵を作ろう

鍵はホスト側で作ります。
※お試しなんでkeyは空ですが、keyは設定するようにしましょう

command
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):  #何も入れずにエンター
Enter passphrase (empty for no passphrase):               #何も入れずにエンター
Enter same passphrase again:                              #何も入れずにエンター
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:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----
+----[SHA256]-----+

ssh-copy-idを使って鍵を送り込もう

これもホスト側でやります

command
$ ssh-copy-id ${USER}@${ssh_target}
~~~省略~~~
Are you sure you want to continue connecting (yes/no)?     #yesを入力してエンター
~~~省略~~~
${USER}@${ssh_target}'s password:                          #接続先のパスワードを入力してエンター

これでパスワードなしでSSH接続ができるようになりました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0