Overview
Generate private key file
Enter the following command in the client terminal
ssh-keygen -t rsa
The private key file generated by ssh-keygen -t rsa will be different every time.
If the file "~/.ssh/id_rsa" exists, you will be prompted whether to overwrite the file. At this time, you can choose "n" not to overwrite the file and use the existing one. id_rsa file If "y" is selected, the " /.ssh/id_rsa" file
will be regenerated . Next, you will be prompted to enter passphrase, press Enter to confirm using an empty passphrase, and press Enter again to confirm (passphrase can also be output here, which is equivalent to the password for ssh login). Then the id_rsa file and id_rsa.pub file ( in the /.ssh directory) will be regenerated.
Execute the scp remote copy command in the terminal
scp /Users/shaarawy18/.ssh/id_rsa.pub [email protected]:~/.ssh
Copy the generated id_rsa.pub file to the ~/.ssh directory of the remote server.
At this time, you also need to enter the root user password for access.
Append the public key to the authorized KEY
Enter the following command in the server terminal
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
If the "/.ssh/authorized_keys" file already exists on the remote server , you need to edit the " /.ssh/authorized_keys" file on the server and append the contents of the "id_rsa.pub" file on the client machine to "~/.ssh/ authorized_keys" file.
If there is no "~/.ssh/authorized_keys" file on the server, execute the following command
cp id_rsa.pub authorized_keys
That is, copy the public key to the authorized_keys file
Test whether the configuration takes effect
ssh [email protected]
reference
Configuration steps for setting up ssh password-free login to linux