What are SSH keys?
As an alternative to password-based login, SSH allows authentication using what are called SSH keys (more precisely: SSH key pairs).
The advantage of using SSH keys is that they allow server connection without user interaction, such as entering a password, and thus the possibility of performing automated actions.
Moreover, key data is generated randomly and is therefore much harder for attackers to guess than a simple password. For this, a public key is created to be stored on your vServer. Additionally, a private key is kept securely on your own PC.
To use SSH keys, you need:
- an SSH client software
On Linux, macOS, and Windows with Babun, the SSH client is directly installed in the system and can be used from the terminal.
To create a new SSH key pair, enter the following command in your terminal and confirm with “Enter”:
openssh-keygen -t rsa
Additional information will then be requested, which you will need to enter. In parentheses, you will see the suggested value that you can accept by pressing “Enter”. For example, it is suggested to store the generated key data in your user directory under $HOME/.ssh/. From there, the key data will also be automatically loaded later.
Important: If you wish, you can set a password to access your private key at this stage. This is recommended if you do not want others to access your SSH.
On Windows with PuTTY, you will need to use the “puttygen” program provided with PuTTY to generate your keys. You can find a guide for example here.
After generating your SSH key pair, you can deposit the public key on your vServer. This can be done, for example, during the system reinstallation directly via our interface or after first connecting to the server via SSH with a password.
In the latter case, proceed as follows after connecting to the server:
- Ensure that the directory “$HOME/.ssh” exists
mkdir $HOME/.ssh - Create the file “$HOME/.ssh/authorized_keys” and paste your public key (starting with ssh-rsa) via ctrl+c/ctrl+v. Alternatively, you can also use the “ssh-copy-id” tool on Linux and macOS.
nano $HOME/.ssh/authorized_keys - Save the changes in the file (ctrl+o) and close it (ctrl+x)
On your next connection, your SSH key will now be used.