Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

On my home network I have a server running Ubuntu and another desktop running Windows 7. I'm using cygwin on the Windows machine to ssh into the server. I attempted to set up keys between these two machines. On the Windows machine I created keys using ssh-keygen -t rsa. I then 'scp'ed the resulting to the server and placed it in the ~/.ssh/authorized_keys file. As far as I know that should be all I need to make this work. But, as you may have guessed, it isn't.

I'm trying to ssh using username@ My guesses (that I haven't been able to get great information on) are that I might need to set something up a bit different to use cygwin or that it could have something to do with using the ip address rather than the hostname... Any directions or ideas?

share|improve this question
up vote 5 down vote accepted

It's probably a permissions issue on either your ~/.ssh directory or your ~/.ssh/authorized_keys file.

Your ~/.ssh directory should be chmod'd to 700 and your authorized_keys file should be chmod'd to 644 at the very least. If you check your /var/log/secure log file, it should give you some hint as to the reason it's failing.

share|improve this answer
This is what the permissions were set to to begin with I believe. I found in the /var/log/auth.log file some error messages leading me to believe my key got corrupted somehow...? I regenerated my keys and uploaded them and things seem to work now. Thanks! – Hector Scout Aug 19 '10 at 3:22
Another reason for failure can be linebreaks in authorized_keys that don't belong there – Tobias Kienzler Nov 14 '13 at 15:50

If you are having authentication problems with ssh, the first thing to investigate is what the client says with some debugging:

% ssh -v host
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/david/.ssh/id_dsa
debug1: Server accepts key: pkalg ssh-dss blen 433
debug1: Enabling compression at level 6.
debug1: Authentication succeeded (publickey).

is a successful publickey connection.

% ssh -v host
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/david/.ssh/id_dsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/david/.ssh/identity
debug1: Trying private key: /home/david/.ssh/id_rsa
debug1: Next authentication method: password
david@ace's password: 

This doesn't really offer much information as to why publickey authentication was being refused. The best information is available on the server. Sshd will log to the AUTH syslog facility, so you can find information where ever that is logged to (in the case of Debian /var/log/auth/).

Aug 19 08:18:36 ace sshd[10100]: Authentication refused: bad ownership or modes 
       for directory /home/david/.ssh

This tells us that the permissions for .ssh is wrong and we can easily fix it.

Aug 19 08:26:41 ace sshd[12156]: error: key_read: uudecode

This tells us that it failed to read that particular key, so we know to fix that.

If you don't get any useful information from the logs, you can turn up the logging. Edit /etc/ssh/sshd_config and change the LogLevel line to:

 LogLevel DEBUG

Then run

 /etc/init.d/ssh reload

Now when you try to connect you should see some logs like:

Aug 19 08:32:12 ace sshd[13537]: debug1: Checking blacklist file 
Aug 19 08:32:12 ace sshd[13537]: debug1: Checking blacklist file 
Aug 19 08:32:12 ace sshd[13537]: debug1: temporarily_use_uid: 1002/513 (e=0/0)
Aug 19 08:32:12 ace sshd[13537]: debug1: trying public key file 
Aug 19 08:32:12 ace sshd[13537]: debug1: fd 4 clearing O_NONBLOCK
Aug 19 08:32:12 ace sshd[13537]: debug1: matching key found: file 
      /home/david/.ssh/authorized_keys, line 1
Aug 19 08:32:12 ace sshd[13537]: Found matching DSA key: 

This was a successful login.

If you need more information, you can use DEBUG2 and DEBUG3 to get further information. Don't forget to change your log level back again (probably to INFO) when you've fixed the problem.

share|improve this answer

The permissions are important for the ~/.ssh/authorized_keys file. The file itself must not have permissions that allow anyone else to write to it chmod go-rwx ~/.ssh/authorized_keys Also, the .ssh directory must not allow writes to it chmod go-rwx ~/.ssh Your home directory should also not allow writes chmod go-w ~/

The reason for this is if anyone else was able to write to your directory (via group permission or other permission) then it would be quite easy for someone to cram authorized keys in there without your knowledge. If your home directory allows writes, then someone could recreate the .ssh directory and its contents.

share|improve this answer

Some distros provide a tool (it's really a shell script) called ssh-copy-id. I find using this gets around a lot of the headaches with copying the .pub portion of a user's key to a remote account's authorized_keys file.


$ ssh-copy-id user@remotehost

You can even tell it different keys to copy (it defaults to the id_rsa* keys.

$ ssh-copy-id -i ~/.ssh/ user@remotehost

This script also takes care of creating the user's $HOME/.ssh directory on remotehost as well and set's the permissions up correctly.

$ ssh-copy-id --help
Usage: /usr/bin/ssh-copy-id [-i [identity_file]] [user@]machine

It has a basic man page to go along with it. On my Red Hat based distros (Fedora, CentOS, RHEL) it was part of the stock openssh-client package!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.