LoginSignup
3
4

More than 5 years have passed since last update.

githubとかbitbucketとか色々公開鍵を使いまわしたいとき

Posted at

はじめに

bitbucketとか、色んな所でsshの公開鍵を共有してるんですが、
今回githubの公開鍵を追加して、いざssh -T git@github.comで疎通確認したら

Permission denied (publickey).

が発生したので、もう二度と同じ過ちを侵さない為に備忘録的に書いておく。

各種公開鍵を作った場合、configファイルを修正し、sshdの再起動を行う必要がある。

step1. 公開鍵登録

$ ssh-keygen -t rsa

適当に鍵作ります。
私は、id_rsa_for_githubという名前で作りました

step2. 公開鍵をgithubに登録する

$ cat ~/.ssh/id_rsa_for_github.pub

githubの設定ページから登録しておきます。

step3. configファイルを修正

$ vi ~/.ssh/config

--- 下記を追記して保存
Host github.com
  User git
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_for_github
  IdentitiesOnly yes

step4. sshdの再起動

$ sudo service sshd restart

step5. githubの疎通確認

$ Hi [github account name]! You've successfully authenticated, but GitHub does not provide shell access.

これでOKです。

3
4
1

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
3
4