Table of Contents
How to create and setup an SSH key
-
Open the ssh config file:
$ ee /etc/ssh/sshd_config -
Edit/Add the following options as such:
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 -
Refresh the settings:
$ service sshd reloadNote: by doing
reloadinstead ofrestart, the already connected ssh connections will stay connected and working -
Generate and Add a random RSA key following the next steps:
-
Generate the 4096 bits rsa key:
$ ssh-keygen -t rsa -b 4096Note:
Generating public/private rsa key pair.can take few seconds -
It will ask for the output name, but leave it empty and press ENTER:
Enter file in which to save the key (/root/.ssh/id_rsa): -
It will ask for the passphrase: (min #pass>4 character length)
Enter passphrase (empty for no passphrase):Enter same passphrase again:Note: using a passphrase instead of leaving blank is highly suggested!
-
Now you have two files inside
/root/.ssh:id_rsaandid_rsa.pub. Save both of them in your computer.Note: you can ignored the printed key fingerprint and key’s randomart image.
-
Add the public key in the authorized keys:
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys2_Note:
~is the name of the current user. If root, it will be/root. -
Now delete the generated keys: (after you saved a copy of them in your computer)
$ rm ~/.ssh/id_rsa ~/.ssh/id_rsa.pub
Note: you don’t need to refresh anything to enable and use the new key.
Note2: you can use any name instead of
id_rsa. -
How to convert a private SSH key into PPK
Some applications (winscp/navicat) require a private key in ppk format. You can do so by:
- Installing puttygen.exe (inside the putty package)
-
Opening it, and loading the private key
id_rsaby doing Conversions -> Import key -
Save the generated key by pressing the button Save private key as
id_rsa.ppk
To log in with WINSCP:
- Open the relative server’s settings
- Don’t specify any password (must be blank)
-
Specify the
id_rsakey in Advanced -> SSH -> AuthenticationNote: It will automatically convert the
id_rsakey toid_rsa.ppk
To log in with NAVICAT: (implies you use an ssh tunnelling)
- Open the Connection Properties of the specified server
- In the SSH tab you specify:
- Authentication Method: Public Key
- Private Key:
id_rsa.ppk
To login with root forbidding any password and allowing only the rsa ssh key:
-
Open the ssh config file:
$ ee /etc/ssh/sshd_config -
Edit/Add the following option as such:
PermitRootLogin without-passwordNote: since fbsd 10.3,
without-passwordhas an alias calledprohibit-password -
Refresh the settings:
$ service sshd reloadNote: by doing
reloadinstead ofrestart, the already connected ssh connections will stay connected and working
Since FreeBSD 13
Since Freebsd 13 the /root/.ssh/.authorized_keys folder and file are missing.
You just need to recreate them and use the correct privileges, otherwise the server will refuse the key (e.g. if you use 777).
mkdir -p /root/.ssh
chmod 700 /root/.ssh
touch /root/.ssh/.authorized_keys
chmod 400 /root/.ssh/.authorized_keys
The RSAAuthentication option is no more required and can be removed too.



