如何管理〜/ .ssh目录中的多个ssh密钥 [英] How to manage multiple ssh keys in the ~/.ssh directory
问题描述
$ git push origin master
我相信我们都会不时发现这个错误:权限被拒绝(publickey)。
致命:无法从远程存储库读取。
请确保您拥有正确的访问权限
并存在存储库。
典型的补救措施是简单地创建一个公钥/私钥对并与你的git主机共享在我的情况下bitbucket,与他们的说明)
事情是,我有很多帐户需要我有一个公钥/私钥对(例如我需要保存一个密钥来连接AWS ..等等)..所以我做的是我创建这些密钥,并将它们保存在单独的目录中,即
〜/。 ssh $ find。
./awskeys
./awskeys/id_rsa
./awskeys/id_rsa.pub
./bitbucket
./bitbucket/id_rsa
./bitbucket /id_rsa.pub
但是这个错误每隔一段时间就会弹出来。解决它我有将相关的键移回到根〜/ .ssh。这对我来说并不合适。我可以如何可靠地做到这一点?
您可以将它们放在您想要的任何位置,但它们的权限和父文件夹的权限需要严格:
- 父文件夹没有可写权限(对于其他人和所有人)
- 644为公钥
- 600为私钥。
然后:
- 在 <$ c中声明这些不同的键$ c>〜/ .ssh / config文件 (示例)
- 更改远程URL,以便使用描述正确ssh密钥的
〜/ .ssh / config
文件的适当条目使用。
这意味着一个条目:
主机mygithub
用户git
IdentityFile〜/ .ssh / mypath / mykey#无论您的新密钥在哪里生存
IdentitiesOnl y是
允许您将像git@github.com:username / repo这样的网址替换为:
git remote set-url origin mygithub:username / repo
I'm sure we all get this error from time to time:
$ 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.
The typical remedy is to simply create a public/private key pair and share it with your git host (in my case bitbucket, with their instructions)
The thing is though, I have many accounts that require that I have a public/private key pair (for example i need to save a key to connect to AWS.. etc).. so what I do is that i create these keys and save them in separate directories ie
~/.ssh $ find .
./awskeys
./awskeys/id_rsa
./awskeys/id_rsa.pub
./bitbucket
./bitbucket/id_rsa
./bitbucket/id_rsa.pub
but then this error pops up every now and then.. to solve it I have to move the relevant keys back to the root ~/.ssh. this doesn't seem right to me. How can I reliably do this?
You can have them anywhere you want, but their permission and the permission of the parent folders need to be strict:
- no writable access for the parent folder (for others and all)
- 644 for a public key
- 600 for a private key.
You then:
- declare those different keys in a
~/.ssh/config file
(example here) - change the remote url in order to use the appropriate entry of the
~/.ssh/config
file which described the right ssh key to use.
That means an entry like:
Host mygithub
User git
IdentityFile ~/.ssh/mypath/mykey # wherever your "new" key lives
IdentitiesOnly yes
Allows you to replace an url like git@github.com:username/repo with:
git remote set-url origin mygithub:username/repo
这篇关于如何管理〜/ .ssh目录中的多个ssh密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!