问题
I'm working on MacOS and want an SSH/Git login with a seccond ssh-key.
I have two key pairs in ~/.ssh/
id_rsa
id_rsa.pub
id_rsa.gitlab
id_rsa.gitlab.pub
id_rsa and id_rsa.pub are the older key. This key is working fine. But where the second key is needed, i can't login. It trys the first key and fails.
Running this command ssh-add /Users/kevin/.ssh/id_rsa.gitlab helps. But after a reboot, it dosen't work anymore and i must run the command again.
Is there a better solution as run this command after each reboot?
回答1:
The way to use several ssh keys is to use a ~/.ssh/config
Host serverKey1
Hostname server1 # or ip address of server1
User serverUser
IdentityFile ~/.ssh/id_rsa
Host serverKey2
Hostname server1 # or ip address of server1
User serverUser
IdentityFile ~/.ssh/id_rsa.gitlab
You then need to use an scp-syntax for your ssh url:
git clone serverKey1:/my/repo
git clone serverKey2:/my/repo
serverKey1 and serverKey2 are entries in your ~/.ssh/config file in order to pass to ssh the right server, user and identify file (public and private keys)
If those private keys are password-protected, you would still need to add them.
You can see more at this atlassian help page: "Configure multiple SSH identities for GitBash, Mac OSX, & Linux".
来源:https://stackoverflow.com/questions/17142566/macos-terminal-how-to-use-a-seccond-ssh-key