Building and hardening my first Linux server
Tonight I went through steps 1 to 3 of creating a Linux VM with Multipass and hardening it with a firewall and key-only SSH.
This is my first project in a series to learn Linux properly, so I can work on real systems.
The steps
- Privileged user creation. An admin account used for everything from here on.
- SSH hardening. Key-only login, so no password authentication, and root login disabled.
- Firewall. Default deny incoming, allow outgoing, and open up ports 22 (SSH), 80 (HTTP) and 443 (HTTPS).
What I learnt
ls -lashows hidden files.sucan be used to switch user.-
chmodis how you set permissions on folders and files. This is especially important because SSH can ignore your key if the permissions are too open.
Mistakes
-
Looking in the wrong place for keys. I went to
/etc/sshand found the server's host keys. I later found out that host keys prove the server's identity, and user keys prove mine. -
Making
authorized_keysa folder. I usedmkdirinstead of creating a file. -
Pasting an incomplete key from my Mac. I missed
out the
ssh-rsaat the start of the key. -
My sudo wasn't actually working. I created the
user with
sudo adduser lewisadm. I then neededsudo usermod -aG sudo lewisadmto add it to the sudo group.
Next
Part two: installing nginx to serve a page, then digging into logs and setting up fail2ban.