FIX: CentOS configuration ssh password-free login still need to enter passwords

Source: Internet
Author: User

Transfer from https://www.jb51.net/article/121180.htm

First step: Create a secret key in this machine

1. Execute command: ssh-keygen-t RSA

2, after all the way to enter the line, will be in the ~ (home) directory generated. SSH (hidden) folder;

3, there are two files Id_rsa (private key), id_rsa.pub (public key) file

Precautions:

① in the LIUNX environment, to copy the public key or the private key, do not use vim and other editors to open the file to copy and paste;

Because it generates unnecessary carriage returns.

② should use Cat to print the content to the terminal to copy and paste;

Step two: Use Ssh-copy-id to copy the public key to the remote host

Ssh-copy-id [email protected]192.168. 161.132

Copy the secret key to the remote server

The port used in this way is the default 22 for Linux, and if you want to specify a port, you can use:

Ssh-copy-id-i/user name/.ssh/id_rsa.pub '-p port number user name @106.75.52.44 '

' - p 22222 [email protected] '

Here may take a while, anyway I was waiting for a long time, and then show you to enter the password:

[Email protected]106.75.52.44 ' s password:

After entering the password, the display:

Now try logging to the machine, with "ssh '-p 22222 [email protected] '", and check in:
. Ssh/authorized_keys

To make sure we haven ' t added extra keys so you weren ' t expecting.

That's a success!

Step three: Log in remotely

[[email protected] ~]$ ssh [email protected]
Last Login:mon Oct ten 14:18:54 from 192.168.161.135

SSH [email protected]-P 22222

The great pits encountered:

After configuring SSH password-free login, I still prompt for password

Workaround:
First, we're going to check the system's log files.
Tail/var/log/secure-n 20

Where the problem is found: Authentication Refused:bad ownership or modes for file

Literally can be seen as the owner of the directory and permissions are improperly configured, find information: SSH do not want the home directory and ~/.ssh directory to the group has write permission, through the following several commands to change

chmod g-w/home/zhangming
chmod 700/home/zhangming/.ssh
chmod 600/home/zhangming/.ssh/authorized_keys
Then we go to log in, we can enter without the password.

FIX: CentOS configuration ssh password-free login still need to enter passwords

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.