Hello everyone, Big Cat. I wish you a happy New Year's Day in advance, A friend asked me how to log in with a key in Linux, but I couldn't draw a specific conclusion before because I didn't have practice, and sent it to my friend after Baidu. Today, Big Cat will teach you how to use the key instead of the password to log in to Linux. The key points are as follows: VMware8 、 putty 、 puttygen 、 WinSCP 。 The operating systems are Centos7.5 、 Ubuntu16.04.3LTS
First, enter the. ssh directory under the user directory of the Linux system. Prompt: If the. ssh directory does not exist, you can create it manually
The root user is /root/.ssh
Ordinary users are /Home/Your user name/. ssh
After logging in to the system, it is found that the. ssh directory does not exist. Create a
Then comes the command to generate the key
Ssh keygen - t rsa - b Key length
If parameter b is not added, 256 bit rsa encryption is used by default
If you do not use the password, please press Enter to skip
After generating the key, the directory will generate the following files
modify /etc/ssh/sshd_config
RSA Authentication yes # Enable RSA authentication ( Since Centos does not exist in the system, it needs to be added manually )
PubkeyAuthentication yes # Whether to use public key authentication
AuthorizedKeysFile. ssh/authorized_keys # Save location of public key
PasswordAuthentication no # Disable login using password authentication
Enter the key directory and execute the following command
touch authorized_keys
cat id_rsa.pub >> authorized_keys
chmod 600 authorized_keys
Download the key file locally using winscp
For versions before CentOS 7 and ubuntu, please execute:
sudo service sshd restart
CentOS 7, please execute:
systemctl restart sshd.service
Then use puttygen to convert the key
Open Private Key
Save Private Key
Then test login
Then you can see that the newly created private key successfully logs in to the server
centos
ubuntu
This is the end of the tutorial. If you still don't understand, please contact Big Cat for help
This article is from Big Cat Huimeng. Please indicate the source and the corresponding link when reprinting.