SSH key login failure solution in Linux

Source: Internet
Author: User


Today, while I was setting up my SSH key login, I found this strange situation, and I copied my id_rsa.pub key content to the remote Linux host's user A. SSH under the Authorized_keys (this file I created manually) under, but when I log on again, Find that you need to enter a password, amount? It's not science! Then I looked at the remote Linux host's sshd log/var/log/secure found the following log output:

Authentication Refused:bad ownership or modes for File/home/sysadmin/.ssh/authorized_keys
It means my authorized_keys permission problem, I check the file permissions

[Root@zenoss. ssh]# ll Authorized_keys
-rw-rw-r--1 SysAdmin sysadmin 791 August 09:01 Authorized_keys
Then I looked at the Authorized_keys file permissions that other servers generated through the Ssh-copy-id command copy.

[Root@zenoss. ssh]# ll Authorized_keys
-RW-------1 SysAdmin sysadmin 393 August 09:46 Authorized_keys
Sure enough, the permissions are different, I changed the Authorized_keys file permissions to 600, and then the normal key to log in.

To find out why, I looked up the official document Http://man.openbsd.org/sshd_config found one of these configuration parameters

Strictmodes
Specifies whether sshd (8) should check file modes and ownership of the the user ' s files and
Home directory before accepting login. This is normally desirable because novices
Sometimes accidentally leave their directory or files world-writable. The default
Is "yes". This is does not apply to Chrootdirectory, whose permissions and
Ownership are checked unconditionally.

This means: sshd Check the user's home directory and file permission mode before accepting a login, you can turn off the check by setting no, but for security reasons, it is recommended that you do not change this option, and configure the home directory and file permissions are positive solutions!
The normal permissions are as follows:

[Root@zenoss home]# ls-ld sysadmin/
DRWX------. 7 sysadmin sysadmin 4096 August 09:46 sysadmin/

[Root@zenoss sysadmin]# ls-ld. ssh/
DRWX------. 2 sysadmin sysadmin 4096 August 09:46. ssh/

[Root@zenoss. ssh]# ls-l Authorized_keys
-RW-------1 SysAdmin sysadmin 393 August 09:46 Authorized_keys

Normal through the Ssh-copy-id command automatically generated Authorized_keys is 600, there will be no such problems.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.