MacOs password-free login CentOs
environment
The environment for this article is as follows:
- CentOs 7
- MacOs10.12.6
Generate a key
First generate the secret key on the local machine, open the terminal, and enter:
ssh-keygen -t rsa -C xxxxx@
The email address behind is free
Then press Enter, after the execution, a hidden folder of .ssh will be generated under the root directory of the current user.
Let's check this folder
wangjianfengdeiMac:~ wangjianfeng$ cd ~/.ssh wangjianfengdeiMac:.ssh wangjianfeng$ ls id_rsa id_rsa.pub known_hosts wangjianfengdeiMac:.ssh wangjianfeng$
You can see that 3 files are generated, among which id_rsa is the private key file, id_ras.pub is the public key file, and the known_hosts file is ignored.
Upload the key
Execute the command in the ssh directory:
cat id_rsa.pub > authorized_keys
Copy the public key content into authorized_keys.
Next, log in to the remote server and create the .ssh folder
wangjianfengdeiMac:.ssh wangjianfeng$ ssh root@ root@'s password: Last login: Sat Mar 3 15:03:08 2018 from [root@VM_0_14_centos ~]# mkdir ~/.ssh
After logging out, copy authorized_key to the .ssh directory in the server through scp
wangjianfengdeiMac:.ssh wangjianfeng$ scp authorized_keys root@:/root/.ssh/authorized_keys root@'s password: authorized_keys 100% 394 73.1KB/s 00:00
Then try to log in to the remote service:
There are two possible situations here:
- Login successfully: It means the configuration is successful
- Password is required to log in successfully
If you need a password to log in, the configuration has not yet taken effect. Try it with the following steps:
- Log in to the server
- Check the file permissions of the .ssh directory and the file permissions of authorized_keys
.ssh should be 700, authorized_keys should be 600
Modify by following the following command
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
If the above operation is not successful, please run the following command to see the cause of failure:
tail /var/log/secure -n 20
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.