ReynierPM ReynierPM - 2 months ago 9
Git Question

How to setup Github SSH login when host username and Github account are different?

I have the following "fake" configuration:


  • A server: server1

  • A username in server1: user1

  • A private Github repository: repo1

  • A Github account: user2



I have created a SSH key for
user1
on
server1
by running:

ssh-keygen


I have added the
id_rsa.pub
key to the Github account:
user2
.

I have tested SSH connection from
server1
logged in as
user1
to Github by running the following commands:

ssh -T git@github.com
ssh -T -p 443 git@ssh.github.com


Both command were successful meaning I can connect. As soon as I try to run:
git pull
I being asked for
username
and
password
, why?

I am trying to avoid enter the username/password each time I need to perform a pull/commit/push.

The repository is configured as
https
:

remote.origin.url=https://github.com/company/repo.git


Should I change the remote URL from
https
to
ssh
? What I am missing?

Note: is "fake" for not to use real names but the configuration exists.

Answer

You need to use the remote URL to SSH to ensure your SSH key is used: git@github.com:company/repo.git.

The easiest way is probably:

git remote remove origin
git remote add origin git@github.com:company/repo.git