I wanted to generate an SSH key for my GitHub account. Following this guide, I ran ssh-keygen -t ed25519 -C "[email protected]"
. I gave it the filename github_main
and put in a passphrase. All that worked fine.
Running ssh-add ~/.ssh/github_main
gave a problem, but I resolved that by running the command with a slightly different path. It returned Identity added: C:/Users/brent/.ssh/github_main ([email protected])
, so I assumed everything worked.
I then tested the connection with ssh -T [email protected]
. It said I was successfully connected, but GitHub doesn't provide shell access, which looked to me like it worked.
I added the SSH token to my GitHub account, no problems there either. Then, I tried cloning one of my repositories through SSH, which strangely didn't work; it gave the following result:
Cloning into 'my-repo'...
[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.
I tried cloning the same repository with the HTTPS and that worked fine. After about an hour of googling and searching, I had read multiple times that the file name has no influence on the result, yet I decided to try renaming the files to the original names. I renamed the public key to id_ed25519.pub
and the private key to id_ed25519
. This time, when I tried cloning the repository with the SSH, it asked for the passphrase and cloned the repository. This confuses me a lot, especially since everything I've read so far has told me that the file name does not matter.
Although it works with having the files named id_ed25519
, I'd still like to rename the files since this file name tells me nothing about the key, and that I can only have one key encrypted like this.
CodePudding user response:
You're not using all the default names, which means you need to tell ssh where you put things. To avoid repeating yourself every time, do that in its config, which it looks for in ~/.ssh/config
. First line: addkeystoagent yes
. Second line: host github
. Third line: hostname github.com
. Fourth line: identityfile path/to/your/privateidentityfile
. The host
line starts a block, you can now say git clone git@github:yourghid/yourrepo
and that's enough. You can even add a user git
line for the host, then git clone github:yourghid/yourrepo
. Spelling is up to you, if I was doing a lot of it I'd spell things like gh
, host gh
user git
hostname github.com
identityfile ~/.ssh/id_gh
, then git remote add linux gh:torvalds/linux
works.
Say man 5 ssh_config
, man section 5 is file formats. Bash completion knows this stuff, say man 5
and hit tab a couple times to tell it no really show me all the file formats you've got doc for.