0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GithubにSSHで接続する方法

Posted at

インターネット上では"Git SSH"で調べると色々手順は出てきて、その通りにやっても以下のエラーが出て接続できなかった。

Linux
Cloning into 'xxxxxx'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

んでGithubの公式マニュアルを調べると微妙に手順が違ったのでやった手順を2020年4月現在の最新手順を作成しておきます。

今回の手順はEC2のLinux環境で実施しました。

参考:Github公式の手順

SSH鍵の作成

ssh-keygen -t rsa -b 4096 -C "xxxxxxxxx@xxxxxx.com"

暗号化形式はRSA 4096bitを指定していないとNGなのだろう。

Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

ファイル名はデフォルトでOKだろう。
しかしパスフレーズはきちんと入力しよう。

SSHエージェントの登録

次にSSHエージェントに鍵を登録します。これも抜けている手順が多かったの忘れずにやること。

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

公開鍵をGithubに登録

Githubに公開鍵を登録します。

まずは右上のsettingに進む。

2020-04-29_21h22_11.jpg

次にSSH ang GPG keys を選択。

2020-04-29_21h22_23.jpg

そしたらNew SSH Keyを選択。

2020-04-29_21h22_33.jpg

公開鍵は「~/.ssh/id_rsa.pub」をコピペする。

2020-04-29_21h22_56.jpg

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDJGlvb06S8zt/9BAWV9CRXmo9KahHOlqU7229XC4DkYHcCrnkK1z3/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/VW32OtgbBnbpf8ErnZsZ+s9feZTt/TfOCDSwc8eGBzXxCOh6tSfH3RKaeIAFU76zE+YPWTSSX5wmgpN9dYVmCbR4AcW1g4+XXXXXXXXXXXXXXXXXXXXXXXXXXX/TyiNm9GTHnr0Qn99y1KgDgEHP2VxiNDAGArKzXqNw3C6dKC4h9kTwjrhCYPW4yP0Kebm6rkN9JKG13oMLIdM06QY7WHZnmVuAzzm/cyQenmsxorJskXTM3e6bktNztEdS9N8I9XpMq27X7x+MH1KYVSbv0BdQK/DKzkfelNZkKbKLF9hKRtp9498nG+ScKIYo9YILGmIQdJY8CdOclM2p+6jGzqmZ9Inxbf+EbZVuV6p0KHDfxZL59NxXdEcDfZ2SdwFGJjPp1QBRkawraFwlkJcoYGUqy52/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==

ssh-keygen で鍵を作成するとメールアドレスが付与されるが、コピペしない点に注意。

コピペが終わったらAdd SSH Key

2020-04-29_21h27_10.jpg

Githubとの接続テスト

SSHコマンドで接続確認をします。

ssh -T git@github.com
RSA key fingerprint is XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
RSA key fingerprint is MD5:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.192.72.89' (RSA) to the list of known hosts.
Hi username! You've successfully authenticated, but GitHub does not

上記のように 「You've successfully authenticated」が出ればOK!

SSH接続でGithubからClone

上記の設定が終わったらgit cloneコマンドでクローンしてみます。

git clone git@github.com:username/xxxxxxxxxxxxxx.git

結論

公式のマニュアルを読め!

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?