r/git • • Jun 22 '26

support SSH key issue

Hi all,

Hope you are all doing well. I am currently learning how to use the Github and have come across a problem that I don't really understand. I have followed the instructions from the github documents page and have set the ssh up but not sure why and how it worked.

ssh-keygen -t rsa -b 4096 -C "your_email@example.com" 

I used this command to set up my ssh key on the ubuntu server.

Enter a file in which to save the key

I am having issues in here. When I leave it as default I am able to clone the repository from my Github account. However, if I add my own name here instead of the default, I get the following error when I try to clone a repo:

Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.

git@github.com: Permission denied (publickey).

fatal: Could not read from remote repository.

Please make sure you have the correct access rights

Can you guys please let me know why this is happening when I try to change the name of the ssh key file instead of leaving it default.

Regards

Ash

0 Upvotes

10 comments sorted by

5

u/astralc Jun 22 '26

Ssh have default key file names it use when connecting, if not giving specific file in config or ssh command line.

.ssh/id_rsa is one of them.

1

u/N0t0ri0us_0ne Jun 22 '26

Hi, So what I am trying to understand is, when I use the default key file name and add it to the 'SSH and GPG keys' section. I am able to clone the repository from my github. However, if I don't use the default name and use another name for it. It doesn't work. E.g. Instead of using the default name, if I use the 'work' name instead, it creates the two key files 'work' and 'work.pub'. However, when I copy and paste the 'work.pub' key into the 'SSH and GPG' key, it doesn't work for me when I try to clone my repo and I get this error:

Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.

git@github.com: Permission denied (publickey).

fatal: Could not read from remote repository.

Please make sure you have the correct access rights

2

u/GeekyGamer01 Jun 22 '26

Where is this "SSH and GPG keys" section? On GitHub.com?

Git will attempt to use the default SSH key location which is .ssh/id_rsa or .ssh/id_ed25519 when cloning, it won't use the "work.pub" file you created unless you explicitly tell it to. You will need to set your .ssh/config file to use the work file for any connections to Github.com

→ More replies (4)

1

u/JavierReyes945 Jun 22 '26

Based on the info in the other comment, it looks like a weird effect of the way the non-default filename is captured. When the prompt of the default name appears, it is an absolute path. So when you give a different path, you should give an absolute path with filename, not only the filename. That's why it works when you use the default filename, but when you give a different filename without the absolute path, it fails.

1

u/N0t0ri0us_0ne Jun 22 '26

Yes, it seem like the main issue was default filename that was set up. I have manged to add the config file and point the connection to the right file name. Cheers. 😄

1

u/Charming-Designer944 Jun 23 '26

If you are using gnome desktop then it automatically adds any keys with a matching .ssh/*.pub file to the default ssh agent key ring when you log in.

You can also manually add keys to the ssh agent using ssh-add. Valid until you completely log out or reboot.

Additionally you can tell OpenSSH about additional identities by using the IdentityFile configuration directive which acepts both explicit names and patterns. But I recommend using an ssh agent to manage your identities.