LoginSignup
239
197

More than 5 years have passed since last update.

ssh-copy-idで公開鍵を渡す

Last updated at Posted at 2015-06-26

鍵認証による ssh を行おうとすると ssh する元のサーバで公開鍵を生成してそれを ssh 先のサーバに持って行って.ssh/authorized_keysに追記しないといけない。めんどくさいなぁと思っていたんだが、ssh-copy-idというコマンドで簡単にコピーすることができる。

ssh-copy-id の利用

引数にアカウント@接続先ホスト名を指定して実行する。これはssh接続するときと同じ。

~/.ssh/id_rsa.pubを渡す場合
ssh-copy-id ${USER}@${target_host}

-iオプションで任意の公開鍵を指定することもできる

ssh-copy-id -i ${identity_file} ${USER}@${target_host}

いつも使っていた方法

cat ~/.ssh/id_rsa.pub | ssh ${USER}@${target_host} "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"
239
197
4

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
239
197