How to manage multiple ssh keys in ~ / .ssh directory

I am sure that we always get this error:

$ git push origin master
Permission denied (publickey).
fatal: Could not read from remote repository.

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

A typical tool is to simply create a pair of public and private keys and share it with your git host (in my case, a bitpacket, with their instructions )

The fact is that I have many accounts that require me to have a public / private key pair (for example, I need to save the key to connect to AWS .. etc.). So what I am doing is that I create these keys and save them in separate directories, i.e.

~/.ssh $ find .
./awskeys
./awskeys/id_rsa
./awskeys/id_rsa.pub
./bitbucket
./bitbucket/id_rsa
./bitbucket/id_rsa.pub

but then this error appears from time to time. To solve this problem, I have to move the corresponding keys back to the root ~ / .ssh file. it doesn't seem right to me. How can i do this?

+4
1

, :

  • ( )
  • 644
  • 600 .

:

, , :

Host mygithub
    User           git
    IdentityFile   ~/.ssh/mypath/mykey # wherever your "new" key lives
    IdentitiesOnly yes

URL-, , git@github.com: /:

git remote set-url origin mygithub:username/repo
+5

Source: https://habr.com/ru/post/1541213/


All Articles