Miguel Dias
Miguel Dias

Reputation: 133

How to use two different github accounts with SSH and Red Hat 7?

I know that are a lot of questions like this one, but no answer was able to solve this problem for redhat. I had a MACOS with two accounts with no big deal, but on Red Hat it just doesn't work.

I have 2 accounts

https://github.com/USER1/REPOSITORY_A.git
https://github.com/USER2/REPOSITORY_B.git

The earlier setup I had been to create an SSH key used for USER1 one on:

~/.ssh/id_rsa.pub 

and the second USER2 on:

~/.ssh/USER2/id_rsa.pub

Added the ssh keys like:

ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/USER2/id_rsa

I had to add each key its own account SSH keys on github. And than I had to set up my config like this:

vi ~/.ssh/config

Host github.com
    Hostname ssh.github.com
    Port 443
    AddKeysToAgent yes
    IdentityFile ~/.ssh/id_rsa
    User git

Host user2-github.com
    HostName github.com
    AddKeysToAgent yes
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/user2/id_rsa
    User git

Host *
    AddKeysToAgent yes
    IdentityFile ~/.ssh/id_rsa

and than I had to set up the USER2 local repository a remote host like:

git remote set-url origin [email protected]:user2/REPOSITORY_B.git

On MACOS everything worked like a charm, but on redhat, when I try to push on the local (USER2) repository, it tries to use "USER1" credentials... I can't find a solution, so I think I need your help...

How to use two different github accounts with SSH and Red Hat 7?

Upvotes: 1

Views: 125

Answers (1)

VonC
VonC

Reputation: 1324258

Firsrt, on RedHat, do check the remote URL used:

git remote -v

If you see https:// in there, no amount of SSH tweaking would help: SSH keys would be ignored. git config credential.helper might show you a credential cache in place, which would have cached USER1 credentials (username/password)

Secong, make sure your URL is user2-github.com:user2/REPOSITORY_B.git (no need for git@, since the user git is specified in the SSH config file)

Upvotes: 0

Related Questions