Login with a key¶
SSH logging in using the RSA
key - increases the security of user authentication with the server and significantly hinders the use of some forms of SSH attacks (e.g. bruteforce). It makes it difficult for unauthorized persons to access the server console.
Generating RSA keys on Windows¶
- Download and run the free application
PuTTygen
(from here ) for generating keys. - Leave the default values (
SSH-2 RSA
, key length2048 bits
), clickGenerate
. - When the key is generated, move the mouse in the area designated by the program.
- In the next window, enter the security password for the generated keys twice.
- Go to
Conversions
and selectExport OpenSSH key
to save the private key for OpenSSH. If you need a private key for PuTTY, you can selectSave private key
to save the private key inPuTTY Private Key Files (*.ppk)
format. - The content of the window (after
Public key for pasting into OpenSSH authorized_keys file:
) save in the account to the file~/.ssh/authorized_keys
. If the file is missing, the path~/.ssh/authorized_keys
should be created.
Generate RSA keys on Linux/macOS systems¶
- Execute the command
ssh-keygen -t rsa
, it should show the following message:Generating public/private rsa key pair. Enter file in which to save the key (~/.ssh/id_rsa):
- Do not change anything, press
ENTER
. - Enter the security password for the generated keys twice:
Your identification has been saved in ~/.ssh/id_rsa. Your public key has been saved in ~/.ssh/id_rsa.pub.
- Receiving the above message means that there are two keys, one private (located in
~/.ssh/id_rsa
) and one public (located in~/.ssh/id_rsa.pub
) .
Login to the server from Windows¶
In the case of logging in from Windows, run PuTTy
, go to the Connection
tab, then Data
. Enter the account login
in the Auto login username
field, then go to the SSH
and Auth
tabs and enter the path to our private key in the Private key file for authentication
field. Save the settings by going back to Session
and clicking Save
.
Login to the server from a Unix system¶
Transfer the public key to the server with the command:
ssh-copy-id -i ~/.ssh/id_rsa.pub LOGIN@SERVER
Then log in to the server with the command:
ssh LOGIN@SERVER