LoginSignup
31
33

More than 5 years have passed since last update.

ssh-copy-idで公開鍵をリモートホストへ登録する

Posted at

はじめに

ssh-copy-idを利用して、公開鍵をリモートホストへ登録する方法を記述します。

環境

  • CentOS 6.5
  • openssh 5.3p1

動作確認

  • 認証用の鍵を生成します。
$ ssh-keygen
$ ls -la ~/.ssh
drwx------. 2 admin admin 4096 Sep 25 04:39 .
drwx------. 4 admin admin 4096 Sep 25 04:29 ..
-rw-------. 1 admin admin 1675 Sep 25 04:39 id_rsa
-rw-r--r--. 1 admin admin  403 Sep 25 04:39 id_rsa.pub
-rw-r--r--. 1 admin admin  412 Sep 25 04:29 known_hosts
  • ssh-copy-idでリモートホストへ公開鍵を登録します。
$ ssh remote-host ls -la ~
drwx------. 2 admin admin      4096 Sep 25 04:31 .
drwxr-xr-x. 3 root  root       4096 Sep 10 22:42 ..
-rw-------. 1 admin admin      7763 Sep 25 04:31 .bash_history
-rw-r--r--. 1 admin admin        18 Jul 18  2013 .bash_logout
-rw-r--r--. 1 admin admin       176 Jul 18  2013 .bash_profile
-rw-r--r--. 1 admin admin       124 Jul 18  2013 .bashrc

$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
Now try logging into the machine, with "ssh 'remote-host'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.
  • リモートホスト側の状態を確認します。
$ ssh remote-host ls -la ~
drwx------. 3 admin admin      4096 Sep 25 04:43 .
drwxr-xr-x. 3 root  root       4096 Sep 10 22:42 ..
-rw-------. 1 admin admin      7763 Sep 25 04:31 .bash_history
-rw-r--r--. 1 admin admin        18 Jul 18  2013 .bash_logout
-rw-r--r--. 1 admin admin       176 Jul 18  2013 .bash_profile
-rw-r--r--. 1 admin admin       124 Jul 18  2013 .bashrc
drwx------. 2 admin admin      4096 Sep 25 04:43 .ssh

$ ssh remote-host ls -l ~/.ssh
-rw-------. 1 admin admin 403 Sep 25 04:43 authorized_keys
  • リモートホスト側に登録された公開鍵とローカルホストの公開鍵を比較してみます。
$ ssh remote-host cat ~/.ssh/authorized_keys | diff - ~/.ssh/id_rsa.pub
※ (出力なし)

参考

31
33
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
31
33