Solution to the failure of SSH key login in Linux

Source: Internet
Author: User
Tags chmod ssh


With an SSH key login, it turns out that you can't log in with the key, and I'm not allowed to enter the password. Distress.

Enter SSH connection code

Ssh-i private.key-v User@host.com-p22

There is nothing wrong with the information from the connection.

Debug1:authentications that can Continue:publickey,gssapi-keyex,gssapi-with-mic,password
Debug1:next Authentication Method:publickey
Debug1:offering Public Key:private.key
Debug1:authentications that can Continue:publickey,gssapi-keyex,gssapi-with-mic,password
Debug1:next Authentication Method:password

I've been prompted to sign in with the public key and provided the private key, but I'm prompted to enter the password.

But I use another account to log in, found is OK, you can log in successfully. I copied the successful ' Authorized_keys ' to my user name and found that I still couldn't log in. But verify that the server's sshd function is normal operation, otherwise an account will not be able to log in. I think two user names should be in the same environment, but you can't log in.

Think of the client here the connection does not have more effective information, then think of the server to see the relevant information. ' Vim/var/log/secure ' Check the log. Found that there was such a passage:

Authentication Refused:bad ownership or modes for DIRECTORY/HOME/USER/.SSH

The Internet search for this problem, found that the original is '. SSH ' directory permissions are not right, set the correct permissions:


chmod ~/.ssh

In the process also learned a sshd test mode.


/usr/sbin/sshd-p 10022-d
-d runs in debug mode. The server will run in the foreground and send very detailed debug log information.
The server will only allow access to one connection and no child processes are derived. For debugging purposes only.
Use multiple-D options to output more detailed debugging information (up to 3).
will open a sshd debug mode, create a new 10022 port, when the client is connected to the port, the server will have debug log output on the screen, this time can view detailed information. And then solve the information.

# # Summary
The server user has some permission requirements for SSH directory permissions, and SSH does not work if the permissions are incorrect, the following permissions are recommended as the minimum permissions.


chmod ssh # chmod 755 ssh is okay.
chmod Ssh/authorized_keys.
chmod Ssh/private.key #把密钥的权限也设置为最小

Finally can be happy to program again.

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.