Sunday, April 01, 2007

svn over ssh prompts for the wrong username

It is time again for one of these rather low level bits :)
The company I am currently working for uses subversion as version control system. The server is setup to use svn+ssh protocol only. Initially I tried to access the source code like this:

svn --username hardy.ferentschik checkout svn+ssh://servername/projectname/trunk
.

For some reason svn would then always prompt me for a password for hardy@servername, where hardy is my user name on the local machine. I couldn't really figure out what was going on. It seemed that the user name specified via --username was not getting passed to the ssh client. I then tried:

svn checkout svn+ssh://hardy.ferentschik@servername/projectname/trunk


which worked fine. I completely forgot about this problem for a while. Until yesterday that is. I wanted to configure a svn:external link from one project to another in order to be able to check them out into the same directory. svn:external works similar to cvs ampersand modules and can be a very useful feature.

For the svn:external property I couldn't use the url with my username in it,
since then everyone checking out the project would have to authenticate with my credentials. Not really a solution. I had to use svn+ssh://servername/projectname/trunk. But now of course my problem re-appeared.

First I tried to find a solution in the svn documentation and on the svn forums, but there is really only the --username option. I was already close to giving up when I thought that if I just could tell ssh which user to use. That was the right path and after a little more search I found out about the config file in the .ssh directory. I've never used it before so I did not even know that it existed. Anyway, the simple solution to my problem was to create a config file in my .ssh directory and putting the following in:

Host servername
User hardy.ferentschik

That fixed the problem :) I still would claim that there must be a bug in the svn client implementation when using --username together with svn+ssh. Surely it should pass the user name on to ssh.

I hope this might help someone with similar problems.

Cheers,
Hardy

12 comments:

Anonymous said...

Thanks a lot hardy. It was indeed a very useful blog. I had a similar problem and I could solve it following your solution.

Thanks once again!!
Niraj

Craig Knox said...

Thanks Hardy - this worked like a charm - I was about to start trying to change my short user name on OSX which is a nightmare, but this was much easier!

Daniel said...

thank you very much Hardy. I already wasted most of a day on this problem and your article helped me fix it in 2 minutes!

Anonymous said...

This is the greatest blog posting ever. I've been trying to figure out this problem for hours!

Jochen said...

Thank you.

Maascamp said...

Thank you! Been having this issue and using an ugly workaround for a while. Finally decided enough is enough. This was incredibly helpful.

SoulGrocery said...

Thank you very much! Would have taken me ages to figure out otherwise...

Anonymous said...

Just wanted to pipe in with a "Metoo!" thanks for the fix! spent ages googling for a solution to this!

Nick said...

Wow. THANK YOU. Such a clean solution.

Kervin Ramen said...

Very nice!

Michael said...

Great post worked for me. Thanks for posting.

Anonymous said...

Great, it worked! Note to make sure to chmod og-rwx ~/.ssh/config !