I have my own gitlab account, and I can ssh to it. I can pull and push to it, no problem. This problem popped up when I tried to ssh clone a private repo which I have access to (I have the credentials). I generated and added ssh key to this account. Configured git globally to reflect the username and email of this new account. And even set them in windows credential manager for gitlab. But the weird thing is I can't still do ssh clone. When I do ssh -T git@gitlab.com
I am greeted with my old account. I don't know what else I have to do to ssh clone from this new account.
Asked
Active
Viewed 8,122 times
0

faint-hearted-fool
- 339
- 4
- 14
-
Have you tried this ``git config --list --show-origin``? – Cody Swann Apr 22 '19 at 23:00
-
Yes, I did. And I couldn't find anything that could help. – faint-hearted-fool Apr 22 '19 at 23:02
-
Does that show any other credentials? – Cody Swann Apr 22 '19 at 23:04
-
No, just the new one I set. – faint-hearted-fool Apr 22 '19 at 23:08
1 Answers
1
@bk2204 you are a lifesaver. I created config
file inside ~/.ssh
and added the following according to one suggestion from the link you provided:
# Default Gitlab
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
# Work Gitlab
Host work.gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/work_rsa
And it worked, as I wanted it to. Many thanks!!!

faint-hearted-fool
- 339
- 4
- 14
-
3I'd reccomend using also `IdentitiesOnly yes` to avoid having the agent try a bunch of keys before the right one. See https://stackoverflow.com/questions/4565700/how-to-specify-the-private-ssh-key-to-use-when-executing-shell-command-on-git/11251797#11251797 – ffflabs Apr 22 '19 at 23:30
-
@ffflabs thanks ! Which I could upvote your comment more, thanks, worked for me. – Janpan Jan 20 '21 at 20:58