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 Due to historical reasons your login on machine is 'eddyp'. You're also part of another project Y which is hosted on server 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 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

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 from project Y since you ~/.ssh/config contains a 'user eddyp' clause for host

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

User eddyp

User eddy

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://

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