Written 10/13/2024 , updated at 12/11/2024
First thing I do is change the ubuntu
user password, and update the system:
passwd
, save this in a password manager, like 1Password or Proton Passsudo apt update && sudo apt upgrade -y
Then I reboot
the system. It’s good to make sure everything is up-to-date.
SSH and security
First thing is to copy over my SSH keys to the server. On my local machine, type ssh-copy-id ubuntu@15.204.234.44
, re-enter the user’s password and you’re good to go with SSH!
Local SSH settings
To make it just that much easier to work with, I edited my local SSH configuration ~/.ssh/config
to save the server I am working on:
Once that is set, I can simply SSH into the server with ssh word
, great!
Server SSH settings
We really want to secure our main entrypoint to the server, and there are a couple strategies for that. Disabling password authentication, root user access, among others.
SSH into the server, and we want to edit the sshd file, sudo vim /etc/ssh/sshd_config
. Ensure the following settings are turned toggled as such:
then reload the service to apply the settings, sudo systemctl reload ssh
.
Firewall
WARNING: Once enabled, MAKE SURE SSH is allowed through the firewall, else you risk being locked out if your VPS provider doesn’t give you some other means of accessing the VPS.
As for the software, I am going to just go with the default ufw
. Enable it with sudo ufw enable
, and enable SSH access with sudo ufw allow OpenSSH
. You might want to ensure the OpenSSH app specifies the correct port, and you can check that with sudo ufw app info OpenSSH
, which will output something similar to the following:
This enables traffic over port 22, exactly what I need. Reload the firewall with sudo ufw reload
and we should be good to go. Reboot the server and hope you can get back in.
Fail2Ban
I should do more research on this, but seems recommended and standard.
sudo apt install fail2ban