Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
160
Help us understand the problem. What is going on with this article?
@kentarosasaki

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

More than 3 years have passed since last update.

鍵認証による 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"
160
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
160
Help us understand the problem. What is going on with this article?