Adding a public key to ~/.ssh/authorized_keys does not log me in automatically

前端 未结 30 2500
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 03:15

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

相关标签:
30条回答
  • 2020-12-02 03:45

    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.

    0 讨论(0)
  • 2020-12-02 03:46

    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.

    0 讨论(0)
  • 2020-12-02 03:47

    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 ~
    
    0 讨论(0)
  • 2020-12-02 03:47

    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.

    0 讨论(0)
  • 2020-12-02 03:48

    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.

    0 讨论(0)
  • 2020-12-02 03:48

    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
    
    0 讨论(0)
提交回复
热议问题