I have 2 GitHub accounts and an ssh key for each of them. Unfortunately ssh-agent always uses the first key unless I use my 3rd solution but then I can't specify the username for GitHub.
Here is my .bashrc which starts up ssh agent and adds those keys
/usr/bin/keychain --nogui $HOME/.ssh/account1 &> /dev/null;
/usr/bin/keychain --nogui $HOME/.ssh/account2 &> /dev/null;
source $HOME/.keychain/$HOSTNAME-sh &> /dev/null;
Here are the multiple things I've tried for my ~/.ssh/config
- I based it off this https://superuser.com/a/1525769
Host account1.git
User git
HostName github.com
IdentityFile ~/.ssh/account1.pub
Host account2.git
User git
HostName github.com
IdentityFile ~/.ssh/account2.pub
Host github.com-account1
HostName github.com
User git
IdentityFile ~/.ssh/account1
Host github.com-account2
HostName github.com
User git
IdentityFile ~/.ssh/account2
- Only this one works but this solution isn't acceptable since my host is just github.com
https://www.freecodecamp.org/news/how-to-manage-multiple-ssh-keys/
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/account1
IdentitiesOnly yes
Here is the error
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Also I tried this which works
ssh -T [email protected]
These other ssh calls don't work
ssh -T git@github-account1
ssh -T [email protected]
ssh -T [email protected]
I suspect that I'm not using the correct host but I honestly don't know why it would be incorrect.
Here's my GitHub account https://github.com/xuhu55
so you can substitute xuhu55 where account1 appears.
-Tis account name, not target host?@is the host, not the accout name, why do you expectgithub-account1.comorxuhu55.githubto work, is there such host?