Procédure
To secure SSH access to your LWS VPS, it is recommended to completely disable password authentication in favor of an SSH key, then install fail2ban. This setup protects your server against brute-force attacks and eliminates the risks associated with intercepted or guessed passwords. In this tutorial, you will copy your public SSH key, adjust the SSH configuration to override cloud-init default settings, then install and verify fail2ban's active protection.
Open a terminal on your computer and connect to the server using the root password received in your delivery email. During the first connection, accept the server key fingerprint by typing yes. Once connected, immediately end the session by running exit to return to your local machine.
ssh root@203.0.113.10
exitFrom your computer, use the ssh-copy-id command to copy your public key to the server. Enter your root password one last time when the terminal prompts you. If you had already added your SSH key during the order or reinstallation from the KVM panel, this step is not necessary.
ssh-copy-id root@203.0.113.10Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@203.0.113.10'"
and check to make sure that only the key(s) you wanted were added.Reconnect to your VPS via SSH from your computer. The connection should be established instantly without asking for the server root password, confirming that your public key has been installed correctly.
ssh root@203.0.113.10List the files present in the /etc/ssh/sshd_config.d/ directory and display the contents of 50-cloud-init.conf. This file enables password authentication. Since the SSH server keeps the first directive encountered when reading files in alphabetical order, your own configuration must necessarily be read before it.
ls /etc/ssh/sshd_config.d/
cat /etc/ssh/sshd_config.d/50-cloud-init.confPasswordAuthentication yesOpen the nano editor to create the file 00-key-only.conf. The 00 prefix ensures that this file will be processed before 50-cloud-init.conf. Add the directives disabling passwords and limiting root access to keys, then save with Ctrl+X, confirm with O (or Y depending on the language), and press Enter.
nano /etc/ssh/sshd_config.d/00-cles-uniquement.conf# SSH login by key only
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-passwordRun sshd -t to check for syntax errors, then verify the active values with sshd -T. Note that permitrootlogin displays without-password, which corresponds to prohibit-password. If everything is correct, reload the SSH service to apply the new settings without interrupting your session.
sshd -t
sshd -T | grep -E "^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin)"
systemctl reload sshpermitrootlogin without-password
passwordauthentication no
kbdinteractiveauthentication noWithout closing your active session, open a second terminal window on your computer. First try a connection by forcing key rejection with the PubkeyAuthentication=no option: the server must refuse access. Then start a normal connection: key-based authentication should succeed.
ssh -o PubkeyAuthentication=no root@203.0.113.10
ssh root@203.0.113.10root@203.0.113.10: Permission denied (publickey).From your session connected to the VPS, update the Debian repositories list with apt update, then install the fail2ban package. On recent Debian versions, fail2ban automatically enables protection for the SSH service as soon as installation is complete.
apt update
apt install -y fail2banMake sure the fail2ban service is active with systemctl, then query the sshd jail to confirm that filtering works and monitors connections. You can then disconnect with complete peace of mind.
systemctl is-active fail2ban
fail2ban-client status sshd
exitactive
Status for the jail: sshd
|- Filter
| |- Currently failed: 1
| |- Total failed: 3
| `- Journal matches: _SYSTEMD_UNIT=ssh.service + _COMM=sshd
`- Actions
|- Currently banned: 0
|- Total banned: 0
`- Banned IP list:The OpenSSH daemon reads the files in the sshd_config.d folder in alphabetical order and applies the first value it encounters. By using the 00 prefix, your directives are processed before those in 50-cloud-init.conf, which guarantees that password blocking is taken into account.
If you lose SSH access, log in to your LWS customer area and open the KVM / VNC console available for your VPS. This console simulates a physical screen and keyboard connected to the server and lets you correct your configuration files without using SSH.
It is exactly the same setting in OpenSSH. prohibit-password is the recommended modern syntax, but the sshd -T command displays its historical equivalent without-password in the list of active directives.
On recent distributions such as Debian 13, fail2ban automatically configures and starts the jail for the SSH service as soon as the package is installed. You can customize ban durations later in a jail.local file if you wish.
Ask the LWS team and the community. Answers are published after moderation.