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
① 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 @22.214.171.124 '
' - 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]126.96.36.199 ' s password:
After entering the password, the display:
Now try logging to the machine, with "ssh '-p 22222 [email protected] '", and check in:
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
First, we're going to check the system's log files.
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
Then we go to log in, we can enter without the password.
FIX: CentOS configuration ssh password-free login still need to enter passwords