Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to set up a key between my Ubuntu machine and my web server so that I can SSH into it without needing to type a password each time.

I have followed the tutorial found here - - to the letter.

Whilst everything seemed to work, when I try to SSH into the server the next time it still prompts me for a password.

My first question is that the reason I am doing this is so I can SSH onto a specific site on my server, so I set this all up on the server using the username associated with the site (in this case tosbourn) is this right or should I have used root on the server?

The second question is that because on my machine my username is different (it is toby) I think this could stop it from working? Am I correct in this assumption or should this not matter?

As it stands the home directories on both my local machine and server have .ssh in them and I have copied accross the required file and renamed it to authorized_keys (and keys2)

Any help would be greatly appreciated.

share|improve this question
up vote 3 down vote accepted

One thing to check is permissions on the key file on the server. I have found in the past that sshd will not use the authorised_keys file unless the permissions are greatly restricted.

chmod 600 ~/.ssh/authorized_keys

ought to do it.

BTW, I'm using keys generated by PuTTY to access a Linux (Slackware) server and all is well.

share|improve this answer
Also make sure that ~/.ssh is at least 700 (or ssh won't be able to read the directory). – Brendan Long Nov 28 '09 at 21:13
  • Using a normal user is good and actually preferred. You might even consider disabling root logins on the server.
  • If your usernames differ across machines, you have to specify the username on your ssh command line (or in your ~/.ssh/config file): ssh -l username hostname.

On your server, check the system logs in /var/log. I am not sure where failed login attempts get logged on your machine, but look for the log files that have been changed recently after a failed login and you should be able to come up with something.

If that didn't help, try getting a verbose out put from ssh: ssh -v -l username hostname. The output is hard to read and understand, but it might give you a clue about what might have gone wrong.

It is also always worth checking that the public key you put on your server didn't end up there in multiple lines. One public key = one single line in the authorized_keys file.

Finally, are you sure that public key logins are enabled on your server?

share|improve this answer
Thanks for your response. I don't have a config file set up under .ssh, but that should be fine to specific a username each time! Here is some relevant looking output from doing verbose output " debug1: Authentications that can continue: publickey,gssapi-with-mic,password debug1: Offering public key: /home/toby/.ssh/id_dsa debug1: Authentications that can continue: publickey,gssapi-with-mic,password debug1: Trying private key: /home/toby/.ssh/identity The public key is on one line and I will check if it is allowed. – Toby Nov 27 '09 at 21:28

I had trouble with keys on a server running Ubuntu. One way to test is to this on the server:

sudo /usr/sbin/sshd -d -p [some port]

And then connect using

ssh -v server.url -p [same port]

This should give you debug info on both sides. The sshd process will probably be more interesting because it will tell you why it's rejecting the key.

My solution was to just give up and move authorized keys to /etc/ssh/users/[user name]/authorized_keys and then changed /etc/ssh/sshd_config's AuthorizedKeysFile setting:

AuthorizedKeysFile /etc/ssh/users/%u/authorized_keys

It's sort of a brute force solution, but it might solve your problem.

share|improve this answer
It's a good idea to start a debugging server, but I'd have a close look at the system logs first. Moving the authorized keys seems like a drastic measure though. – innaM Nov 28 '09 at 12:16
Yeah, I figured I'd post my solution in case it helps though. I don't use Ubuntu on my server anymore, but I think the problem I had was related to permissions. – Brendan Long Nov 28 '09 at 21:11

I was speaking to the hosts and it would seem that the key I generate needs to be made in Putty on a windows machine, the converted to work on my Ubuntu machine. This doesn't seem right like but I am going to give it a go and see what happens!

Cheers again to Manni for the response.

share|improve this answer
Is your server a Windows machine? I cannot imagine another reason for Putty-generated key to work, and Linux-generated key not to work... – chronos Nov 27 '09 at 22:47

On the client do:


(without passphrase)

and then:

ssh-copy-id username@server

This should set up keyed login.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .