SSH connection asks for password although key is accepted
I'm getting prompted for a password even though it looks like my SSH key is accepted. As far as I can tell, the line "Server accepts key: pkalg ssh-rsa blen 277" in the logs below mean my key is accepted.
Here are debug logs:
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/sam/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug2: input_userauth_pk_ok: fp <<HASH REDACTED>>
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /home/sam/.ssh/id_dsa
debug1: Trying private key: /home/sam/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug2: input_userauth_info_req
debug2: input_userauth_info_req: num_prompts 1
Help much appreciated, everyone I've found who is having SSH problems fails at an earlier point that I'm seeing.
Solution 1:
Your private key was most certainly not accepted, it was only attempted. There are a number of ways SSH key based authentication can fail, and the logging is not really that great so debugging this particular problem is one of my personal pet peeves. I've found that the error is usually a result of one of the following situations.
-
Your
~/.ssh/authorized_keys
file is too open. For your own protectionsshd
attempts to protect you from yourself. If the permissions on your authorized keys file then it will fail the authentication. Runchmod -R go-rwx ~/.ssh
. -
Your public key in
~/.ssh/authorized_keys
is malformed. This could be a result of any number of problems, but the most common is a copy paste issue. Some terminals, when copy/pasting across screens, will interpret a line wrap as a new line. Each entry in theauthorized_keys
file must be a single line. You can check this by changing the size of your terminal emulator and seeing if there's a break, comparing the output ofwc -l ~/.ssh/authorized_keys
against the number of keys that should be in there, or whatever works best for you. Just make sure each key is one line and you should be fine.
Solution 2:
The ssh -v output you pasted suggested that it tried to use the key but that didn't work, so it moved on to keyboard-interactive.
Have you checked the authentication log on the server you are connecting to? (eg, /var/log/auth.log). If your setup at the remote end is incorrect, eg wrong permissions, then ssh -v (or -vv or -vvv) won't tell you this, but it will be logged by sshd.
Solution 3:
In my case, file /var/log/authlog
showed:
[ID 800047 auth.info] Authentication refused: bad ownership or modes for directory
I had checked correct ownership/permissions in .ssh
but the $HOME
had 777 permissions.
Setting 755 permissions on $HOME
allowed sftp to work. Thanks again.
Solution 4:
If you have access to the server (directly or via another login), check the server logs in (say) /var/log/sshd
or /var/log/secure
depending on your system
It is typically caused by a permissions error on your ~/.ssh/authorized_keys
file. Make sure it's not world readable, but crucially that it is readable by the user (sometimes a service user) running sshd
Solution 5:
Permissions of ~/.ssh/authorized_keys
in remote is important (600
for my systems RHEL and Solaris)
Permissions of you home directory in remote is important (700
in my systems)
At the end run sshd
in remote machine in debug mode on another port can be helpful:
sudo /usr/sbin/sshd -p 5555 -dd
5555
is an example port, you can change it. For more info in this regard you can see: http://ubuntuforums.org/archive/index.php/t-2219973.html