osprey's diary

日々の雑感を書き綴ります

Ubuntuでsshで公開鍵認証

 

検証用サーバにかんたんにssh接続できるようにメモ。

ssh-keygenコマンドとssh-copy-idコマンドでできた。

passphraseを空にすることもできる(社内検証用なので今回は気にしない)。

このあと相手側ホストのsshd_configでパスワード認証を切っておく。

 

% ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX user@host
The key's randomart image is:
...snip...
% ssh-copy-id user2@host2
/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
user2@host2's password:

Number of key(s) added: 1

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