1

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 git@user2-github.com: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?

Miguel Dias
  • 83
  • 1
  • 1
  • 6

1 Answers1

0

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)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hi, on the matter of ```git config credential.helper```, there is no cache. It was a good tip, even though that should be it... But no, no cache... About the URL, I did both ways: ``` git@user2-github.com:user2/REPOSITORY_B.git user2-github.com:user2/REPOSITORY_B.git ``` But both gives me the same error: ```ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. ``` Maybe git is ignoring the ssh config file on ```~/.ssh/config``` ? – Miguel Dias Feb 20 '20 at 15:36
  • @MiguelDias ` git@user2-github.com` will ignore your ~/.ssh/config for sure. Try first a `ssh -Tv user2-github.com` – VonC Feb 20 '20 at 15:38