I recently bought an Ali server and learned about the server. Maybe because my network is not good, the ssh login server is always disconnected, so I have to re-enter the password every time. This kind of situation is very annoying. I found some information on the Internet to configure the key-free login, and share it with you.
Note that the situation on my side is that my local windows system is logged in to the remote linux server.
1. Generate a pair of secret keys locally
Type the command in the shell terminal: ssh-keygen -t rsa and press Enter three times to generate a pair of keys.
Generate two files, a private key id_rsa, a public key id_rsa.pub, the file location is in the C:\Users\username\.ssh directory
2. Upload the generated public key to the server
Use the command ssh-copy-id -i ~/.ssh/id_rsa.pub <romte_ip> to upload the local public key directly to the server
Pay attention to the location of your id_rsa.pub here. I operate directly in the .ssh directory, so it is ./id_rsa.pub. The server is also in the form of username@domain name. The domain name here can also be an ip address.
When the following two sentences appear, it proves successful
Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
No need to enter a password to log in directly
At this time, look at .ssh/authorized_key on the server and you can see the same public key as the locally generated public key