A Raspberry Pi

A Raspberry Pi at home needs a new user, SSH that only accepts keys, and regular updates. A port forwarded from the router to the Pi’s SSH makes it reachable for anyone scanning the internet, so reach it from outside through a VPN.

The default user

Older Raspberry Pi OS images came with the user pi and the password raspberry. Since April 2022 that user is gone, and a user is created at first boot. Plenty of old images and tutorials still assume the old one, and worms still try it over SSH.

On a Pi that still has a pi user with a weak or default password, create a new user with a strong password, or install a fresh image.

SSH with keys only

Raspberry Pi’s documentation covers making a key on the computer used to log in, and copying it to the Pi:

ssh-keygen
ssh-copy-id <username>@<ip address>

Windows has no ssh-copy-id, and there the same documentation copies the key over with scp.

Once logging in with the key works, switch off passwords for SSH. In /etc/ssh/sshd_config the setting is PasswordAuthentication no. A file under /etc/ssh/sshd_config.d/ can override it, so check that directory too. Then restart SSH:

sudo systemctl restart ssh

Test it with a login that refuses the key:

ssh -o PubkeyAuthentication=no <username>@<ip address>

The answer is Permission denied (publickey), and a normal ssh still gets in.

Switching off password logins before the key works locks everyone out of SSH. The way back is a keyboard and screen on the Pi itself, or the SD card in another computer.

Updates

sudo apt update
sudo apt full-upgrade

Run these once a week on a Pi that others in the house rely on, such as one running Pi-hole.