Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have created a private/public dsa-keypair. I've put the public key on the server in

~/.ssh/authorized_keys

Everything is set up like my other server, but it seems like the server is just ignoring my efforts.

share|improve this question
    
Check /etc/ssh/ssh_config and /etc/ssh/sshd_config to verify that nothing you want is disabled. –  Kristopher Johnson Apr 30 '09 at 11:21
    
You will want to check sshd_config too. –  Vagnerr Apr 30 '09 at 12:27
    
Thanks. I updated the answer (which originally mentioned only ssh_config). –  Kristopher Johnson Apr 30 '09 at 12:55
    
All of the above discussions are perfect for if you're using an openssh style of ssh. If you're system is using ssh2 then it has a totally wacky different way to manage keys. This article discusses the hows and whats. burnz.wordpress.com/2007/12/14/… –  chris Jun 25 '09 at 2:13
    
In case you already logged out from server and cannot log in due to invalid server configuration then following forces client to use password: ssh <user>@<server> -p <port> -o 'PasswordAuthentication yes' -o 'ChallengeResponseAuthentication no' -o 'PreferredAuthentications password' –  JaakL Aug 22 '12 at 11:33
show 1 more comment

3 Answers 3

up vote 8 down vote accepted

Although your problem may have already been solved by other answeres, I've locked myself out of enough machines from not validating sshd_config changes before signing off so have come up with the below process that might be useful for future debugging of sshd config changes:

DO NOT DISCONNECT an active ssh connection until AFTER testing has verified behaviour is as you expect.

a. verify what you think sshd is supposed to be doing

b. verify the configuration is valid using "-t"

c. start a verbose 'test' version of the server you can live monitor

d. start a verbose 'test' client connection you can live monitor


a. verify what you think sshd is supposed to be doing

Review the sshd configuration file without all the commentary with something like the below (assuming sshd_config is the correct file and in /etc/ssh)

$ grep -v "^#" /etc/ssh/sshd_config | grep -v "^$"

This just clears things out so we verify what we think we're changing (not necessarily whether it is correct or not.)

b. verify the configuration is valid using "-t"

From the man page of the sshd's I'm using,

-t Test mode. Only check the validity of the configuration file and sanity of the keys. This is useful for updating sshd reliably as configuration options may change.

Other changes can have more subtle circumstances. For example, do not disable password authentication until you are sure that the public key authentication is working correctly.

c. start a verbose 'test' version of the server you can live monitor

$ sudo /usr/sbin/sshd -ddd -p 9999

This keeps your existing, working session active, but gives you another instance of sshd to verify your new configuration changes. SSHD is now running in the foreground to a user-defined port (9999 in our example.) and pushing a lot of noisy debug information you can track in /var/log/authlog (or possibly /var/log/auth.log depending on your OS.)

d. start a verbose 'test' client connection you can live monitor

Run the ssh client connection in verbose mode to display on your screen more information that might lead you to better debugging your error.

$ ssh -vvv -p 9999 server-name

You should now have enough information in either the server's log files, or the client's connection screen to isolate your problem.

The solution generally comes down to file permissions (as shown by Magnar and setatakahashi)

Best of luck

share|improve this answer
    
I guess you should also check the ssh_config file on the client end to make sure it is doing what you expect. Use something like the below to grep out comments: > grep -v "^#" /etc/ssh/ssh_config | grep -v "^$" –  samt May 25 '09 at 22:55
    
Well, the client ssh configuration can be fixed at anytime, it's the server you get locked out of if you configured it wrong. –  Soviero Feb 4 '12 at 18:09
add comment

The server will ignore your authorized_keys file if the owner properties are wrong. Changing it to this fixes it:

chmod 0700 ~/.ssh
chmod 0600 ~/.ssh/authorized_keys
share|improve this answer
6  
ssh -vvv -l username server.domain will tell you if your sending a valid key –  Dave Cheney Apr 30 '09 at 11:23
    
Sometimes I've seen sshd complain about bad permissions on the home directory - so I'd add "chmod o-rwx ~" (or at least "chmod o-w ~") to the list as setatakahashi did. This usually becomes obvious when the logfile is monitored - the error messages I've seen there always pointed in the correct direction. –  Olaf May 24 '09 at 14:46
    
This answer seems the most likely, but Dave Cheney's comment is the only way to see what's really going on. Also check server logs. –  dwc May 24 '09 at 15:07
    
This was my problem. I beat my head on this for hours. Thanks so much! –  Sam Soffes Nov 5 '10 at 4:58
1  
This did the trick, but my previous permissions were 0775 and 0644 respectively. Why did reducing the permissions help? Is this a security precaution that's configured somewhere? –  Dean Jun 24 '12 at 18:30
add comment

$ chmod 700 ~

$ chmod 700 ~/.ssh

$ chmod 600 ~/.ssh/authorized_keys

Check for these attributes in /etc/ssh/sshd_config

$ sudo grep PubkeyAuthentication /etc/ssh/sshd_config

$ sudo grep Protocol /etc/ssh/sshd_config

share|improve this answer
2  
Excellent point about ~, you must make sure that nobody other than yourself can write to your home directory, otherwise they could rename your ~/.ssh directory –  Dave Cheney Jun 25 '09 at 2:53
    
that last chmod should be: $ chmod 600 ~/.ssh/authorized_keys not $ chmod 600 ~/.sHh/authorized_keys –  SooDesuNe Feb 3 '12 at 3:03
add comment

protected by Chris S Jun 21 '13 at 13:23

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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