Secure your VPS: SSH keys and a firewall · Galaxium Hosting help
Log in with an SSH key instead of a password and turn on the firewall inside your server (ufw or firewalld).
Your VPS has its own public IPv4 address and full root access, so you secure it from inside the server. Both steps below take a few minutes.
Log in with an SSH key
Keys are safer than passwords.
- On your own computer, create a key if you don't have one:
ssh-keygen -t ed25519. - Log in to the server with the root password (see Connect to your VPS over SSH).
- Add your public key (usually
~/.ssh/id_ed25519.pubon your computer) to the server:
mkdir -p ~/.ssh && chmod 700 ~/.ssh
echo "ssh-ed25519 AAAA... you@laptop" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
- Open a new terminal and check that
ssh root@<your server address>logs in without asking for the password. - Optional: switch password logins off. Set
PasswordAuthentication noin/etc/ssh/sshd_configand runsystemctl restart ssh(orsshd).
Warning: Never paste a private key anywhere you don't trust, and never share one with anyone, including support.
Turn on a firewall
The firewall runs inside your server and decides which incoming traffic gets in.
Ubuntu and Debian (ufw):
apt install -y ufw
ufw allow OpenSSH
ufw allow 80,443/tcp # only if you run a website
ufw enable
AlmaLinux, Rocky Linux, CentOS Stream and Fedora (firewalld):
systemctl enable --now firewalld
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --add-service=http --add-service=https # only for a website
firewall-cmd --reload
Warning: Always allow SSH (TCP 22) before you turn the firewall on, or you lock yourself out. The browser terminal uses SSH too, so it can't get past the rule either. Take a snapshot first, so you can roll back if that happens. On servers with the screen console, you can also log in there and fix the rule.
Docker publishes container ports past ufw by default. If you use Docker, bind containers to 127.0.0.1 or put a reverse proxy in front.
One-click apps list the ports they need on their app page. Open the public ones in your firewall.