3
2

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.

git@github.com: Permission denied (publickey) が出たときの対処法

Posted at

Permanently added the RSA host key for IP address

Warning: Permanently added the RSA host key for IP address '[ip address]' to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

対処法

$ ssh-keygen -R '[ip address]' 

Please make sure you have the correct access rights

$git clone git@github.com:xxxxxx/xxxxx.git
Cloning into 'docker-elk'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights

対処法

鍵を生成

$ ssh-keygen -t rsa -C [mail address]
Enter file in which to save the key (/home/vagrant/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/[pc name]/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/[pc name]/.ssh/id_rsa.
Your public key has been saved in /Users/[pc name]/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:[hash] [mail address]
The key's randomart image is:
+---[RSA 3072]----+
|      o o.E      |
|     o . .       |
|    x x     .    |
|     x x   x .   |
|    * * x + + .  |
|   o = . x = . . |
|    . ..+x+ . .  |
|       +xxx* o . |
|       =BBBo=..  |
+----[SHA256]-----+

(一応適当に書き換えてあります)

鍵をコピー

$ less ~/.ssh/id_rsa.pub
ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [mail address]

[mail address]以外の部分をコピーする

github settingへ遷移

スクリーンショット 2021-05-28 9.08.01.png

「New SSH Key」を押下

鍵を追加

スクリーンショット 2021-05-28 9.19.53.png

疎通確認

ターミナルに戻り疎通を確認する

$ vim ~/.ssh/config 
Host github
  HostName github.com
  IdentityFile ~/.ssh/id_rsa
  User git

これを貼り付ける

ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '[ip address]' to the list of known hosts.
Enter passphrase for key '/Users/[pc name]/.ssh/id_rsa': 
Hi [git config name]! You've successfully authenticated, but GitHub does not provide shell access.

こんな感じの、successfullyメッセージが表示されたら完了。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?