I added the public SSH key to the authorized_keys file. ssh localhost
should log me in without asking for the password.
I did that and tried t
In my case I needed to put my authorized_keys
file in .openssh
.
This location is specified in /etc/ssh/sshd_config
under the option AuthorizedKeysFile %h/.ssh/authorized_keys
.
I have the home directory in a non-standard location and in sshd
logs I have the following line, even if all permissions were just fine (see the other answers):
Could not open authorized keys '/data/home/user1/.ssh/authorized_keys': Permission denied
I have found a solution here: Trouble with ssh public key authentication to RHEL 6.5
In my particular case:
Added a new line in /etc/selinux/targeted/contexts/files/file_contexts.homedirs
:
This is the original line for regular home directories:
/home/[^/]*/\.ssh(/.*)? unconfined_u:object_r:ssh_home_t:s0
This is my new line:
/data/home/[^/]*/\.ssh(/.*)? unconfined_u:object_r:ssh_home_t:s0
Followed by a restorecon -r /data/
and a sshd
restart.
You need to verify the permissions of the authorized_keys
file and the folder / parent folders in which it is located.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
For more information see this page.
You may also need to change/verify the permissions of your home directory to remove write access for the group and others.
chmod go-w ~
The desperate may also make sure they don't have extra newlines in the authorized_keys file due to copying file id_rsa.pub's text out of a confused terminal.
Make sure that the target user has a password set. Run passwd username
to set one. This was required for me even if password SSH login was disabled.
On that note, make sure your sshd configuration has this line:
PermitRootLogin without-password
Set as the above, and then restart sshd (/etc/init.d/sshd restart
).
Log out and try log in in again!
The default, I believe, is:
PermitRootLogin no