04 April 20
The most secure way to SSH
into a remote server is by using keys instead of logging in with passwords. To enable this, you need to generate a set of keys on your machine that you will SSH
from.
To generate a set of keys, enter the following command into your shell:
ssh-keygen -t rsa -b 4096
The -t
defines the type of key create, which is rsa
. The -b
specifies the number of bits in the key to create. The default value for this option is 3072 bits, which is usually enough. 4096 is more secure.
Now you have generated both a public and private SSH
key that is stored in your .ssh/
folder in your home directory. Now you have to copy the public key into the .ssh/
of the remote server you wish to SSH
into.
To do this, run the following command:
ssh-copy-id USER@HOST
Where USER
is the username on the remote server, and HOST
is the hostname of the remote server.