Connect to SSH using the keys

To connect to SSH without entering a password, you can generate public and private keys on the local north, then copy it to a remote machine, then the password will not be asked when connecting to it.

On the local machine, generate the keys:

sudo ssh-keygen -t rsa

Copy the public key to the remote server:

sudo ssh-copy-id -i ~/.ssh/id_rsa.pub -p PORT USER@HOST

If an error occurs while copying the key, you can manually copy the line from id_rsa.pub to the remote server in the authorized_keys file.

The specified commands must be executed from the user from whom the connection will be made.
For example, if from root, then you need to execute the following command before the two commands:

sudo -i

You can remove the host by:

ssh-keygen -f "/home/user/.ssh/known_hosts" -R [HOST]:22

See also:
Installing and Configuring SSH

Leave a comment

Leave a Reply

Discover more from IT Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading