最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

git - Can't SSH to GitHub using key saved in a custom lcoation - Stack Overflow

programmeradmin5浏览0评论

When I generate an ssh key in a different path than the default I can't access by ssh in github, I don't know what the problem is, but I know I have tried many times to generate and use a ssh with a different path than the default and all my attempts have failed.

Can someone explain why? Or say where am I going wrong

It works:

PS C:\Users\sjoao\.ssh> ssh-keygen -t ed25519 -C "[email protected]"
Generating public/private ed25519 key pair.
Enter file in which to save the key (C:\Users\sjoao/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\sjoao/.ssh/id_ed25519
Your public key has been saved in C:\Users\sjoao/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:sBpycUHR17hJwxtmDZFJgZSiNP9XBdlBP41AKQIEc5w [email protected]
The key's randomart image is:
+--[ED25519 256]--+
|    o=B*.==@+*o. |
|    ooE.= & =.oo.|
|   ..+o. * B ...o|
|    .o.o  + .   .|
|  . o ..S  .     |
|   o o  . .      |
|    .    .       |
|                 |
|                 |
+----[SHA256]-----+
PS C:\Users\sjoao\.ssh> Start-Service ssh-agent
PS C:\Users\sjoao\.ssh> ssh-add .\id_ed25519
Identity added: .\id_ed25519 ([email protected])
PS C:\Users\sjoao\.ssh> Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | Set-Clipboard
PS C:\Users\sjoao\.ssh> git clone [email protected]:jottaVictor/tictactoegame.git
Cloning into 'tictactoegame'...
The authenticity of host 'github (20.201.28.151)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github' (ED25519) to the list of known hosts.
remote: Enumerating objects: 135, done.
remote: Counting objects: 100% (135/135), done.
remote: Compressing objects: 100% (93/93), done.
remote: Total 135 (delta 47), reused 121 (delta 33), pack-reused 0 (from 0)
Receiving objects: 100% (135/135), 45.16 KiB | 388.00 KiB/s, done.
Resolving deltas: 100% (47/47), done.

Dont Work:

PS C:\Users\sjoao\.ssh> ssh-keygen -t ed25519 -C "[email protected]"
Generating public/private ed25519 key pair.
Enter file in which to save the key (C:\Users\sjoao/.ssh/id_ed25519): .\test
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in .\test
Your public key has been saved in .\test.pub
The key fingerprint is:
SHA256:pOwOkkTVPPMaNn01y6VVmp1+B2P0MQgsfpDeq0KV7pM [email protected]
The key's randomart image is:
+--[ED25519 256]--+
|    .o    o.. o+.|
|   .  =  + .ooo=+|
|  .    =+ =o **.o|
| .   .+oo=.o+..o |
|  .  .o+S.. .  .o|
| . . ... . .    o|
|  o . o . o      |
|   . o . E       |
|      . . .      |
+----[SHA256]-----+
PS C:\Users\sjoao\.ssh> Start-Service ssh-agent
PS C:\Users\sjoao\.ssh> ssh-add .\test
Identity added: .\test ([email protected])
PS C:\Users\sjoao\.ssh> Get-Content $env:USERPROFILE\.ssh\test.pub | Set-Clipboard
PS C:\Users\sjoao\.ssh> git clone [email protected]:jottaVictor/tictactoegame.git
Cloning into 'tictactoegame'...
The authenticity of host 'github (20.201.28.151)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github' (ED25519) to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

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

The only difference is my answer to 'Enter file in which to save the key (C:\Users\sjoao/.ssh/id_ed25519):' I add both in the list of ssh-keys of github

When I generate an ssh key in a different path than the default I can't access by ssh in github, I don't know what the problem is, but I know I have tried many times to generate and use a ssh with a different path than the default and all my attempts have failed.

Can someone explain why? Or say where am I going wrong

It works:

PS C:\Users\sjoao\.ssh> ssh-keygen -t ed25519 -C "[email protected]"
Generating public/private ed25519 key pair.
Enter file in which to save the key (C:\Users\sjoao/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\sjoao/.ssh/id_ed25519
Your public key has been saved in C:\Users\sjoao/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:sBpycUHR17hJwxtmDZFJgZSiNP9XBdlBP41AKQIEc5w [email protected]
The key's randomart image is:
+--[ED25519 256]--+
|    o=B*.==@+*o. |
|    ooE.= & =.oo.|
|   ..+o. * B ...o|
|    .o.o  + .   .|
|  . o ..S  .     |
|   o o  . .      |
|    .    .       |
|                 |
|                 |
+----[SHA256]-----+
PS C:\Users\sjoao\.ssh> Start-Service ssh-agent
PS C:\Users\sjoao\.ssh> ssh-add .\id_ed25519
Identity added: .\id_ed25519 ([email protected])
PS C:\Users\sjoao\.ssh> Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | Set-Clipboard
PS C:\Users\sjoao\.ssh> git clone [email protected]:jottaVictor/tictactoegame.git
Cloning into 'tictactoegame'...
The authenticity of host 'github (20.201.28.151)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github' (ED25519) to the list of known hosts.
remote: Enumerating objects: 135, done.
remote: Counting objects: 100% (135/135), done.
remote: Compressing objects: 100% (93/93), done.
remote: Total 135 (delta 47), reused 121 (delta 33), pack-reused 0 (from 0)
Receiving objects: 100% (135/135), 45.16 KiB | 388.00 KiB/s, done.
Resolving deltas: 100% (47/47), done.

Dont Work:

PS C:\Users\sjoao\.ssh> ssh-keygen -t ed25519 -C "[email protected]"
Generating public/private ed25519 key pair.
Enter file in which to save the key (C:\Users\sjoao/.ssh/id_ed25519): .\test
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in .\test
Your public key has been saved in .\test.pub
The key fingerprint is:
SHA256:pOwOkkTVPPMaNn01y6VVmp1+B2P0MQgsfpDeq0KV7pM [email protected]
The key's randomart image is:
+--[ED25519 256]--+
|    .o    o.. o+.|
|   .  =  + .ooo=+|
|  .    =+ =o **.o|
| .   .+oo=.o+..o |
|  .  .o+S.. .  .o|
| . . ... . .    o|
|  o . o . o      |
|   . o . E       |
|      . . .      |
+----[SHA256]-----+
PS C:\Users\sjoao\.ssh> Start-Service ssh-agent
PS C:\Users\sjoao\.ssh> ssh-add .\test
Identity added: .\test ([email protected])
PS C:\Users\sjoao\.ssh> Get-Content $env:USERPROFILE\.ssh\test.pub | Set-Clipboard
PS C:\Users\sjoao\.ssh> git clone [email protected]:jottaVictor/tictactoegame.git
Cloning into 'tictactoegame'...
The authenticity of host 'github (20.201.28.151)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github' (ED25519) to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

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

The only difference is my answer to 'Enter file in which to save the key (C:\Users\sjoao/.ssh/id_ed25519):' I add both in the list of ssh-keys of github

Share Improve this question edited Mar 20 at 0:53 Chris 138k134 gold badges306 silver badges285 bronze badges asked Mar 19 at 19:04 Victor SantosVictor Santos 232 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 4

The issue is likely because SSH is not automatically picking up your custom key. By default, SSH looks for keys in ~/.ssh/id_rsa or ~/.ssh/id_ed25519. When using a non-default path, you need to explicitly specify it in your SSH config.

Solution:

  1. Edit (or create) your SSH config file:

    notepad C:\Users\sjoao\.ssh\config
    
    
  2. Add the following lines:

    Host github
        IdentityFile C:\Users\sjoao\.ssh\test
        IdentitiesOnly yes
    
    
  3. Save the file and retry your git clone command.

发布评论

评论列表(0)

  1. 暂无评论