Friday, 26 February 2010

How to: git push via ssh; alternative users on the same host

Let's assume you're part of a project X that uses git for version control on a server host.it. Due to historical reasons your login on machine host.it is 'eddyp'. You're also part of another project Y which is hosted on server host.me. In this project you have always used 'eddy' as your ssh login for the git push.

Now, project Y decides to change hosting and moves the repo on server host.it. Since the logins were also migrated, now you have login 'eddyp' for project X and login 'eddy' for project B.

You changed the URI in remote.origin.url, but you are faced with this error when pushing from project Y to server host.it:

Counting objects: 7, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 476 bytes, done.
Total 4 (delta 2), reused 0 (delta 0)
error: unable to create temporary sha1 filename ./objects/56: Permission denied

fatal: failed to write object
error: unpack failed: unpacker exited with error code


The problem is that you are probably trying to login with 'eddyp' on server host.it from project Y since you ~/.ssh/config contains a 'user eddyp' clause for host host.it.


You can avoid this problem and identify to server host.it with different logins depending on the project via a small nice trick using fake hostnames in ~/.ssh/config:


Host eddyp.host.com
User eddyp
Hostname host.it

Host eddy.host.com
User eddy
Hostname host.it


And setting the remote.origin.url setting accordingly in the repo for project Y and project X:


eddy@projx $ git config remote.origin.url ssh://eddyp.host.it/srv/git/projx.git

eddy@projy $ git config remote.origin.url ssh://eddy.host.it/srv/git/projy.git

2 comments:

mountie said...

You could have just changed to remote.origin.url to the form:
eddy@host.it/srv/git/projy.git
and
eddyp@host.it/srv/git/projx.git

and skipped the whole ssh config part.

Anonymous said...

Yes, but that way when providing someone the config info would not be portable.

EddyP