Server access and security
Replace unsafe defaults with SSH keys, limited identities, a default-deny firewall, and a safe change sequence.
Secure access is the first production task. Complete it before deploying an application or placing data on the server.
1. Create and install an SSH key
Run key generation on your workstation:
Protect the private key with a passphrase and never copy it to the server. The .pub file is safe to distribute.
2. Create a named operator
Open a second terminal and verify ssh deploy@203.0.113.10 plus sudo -v. Keep the root session open until all access changes work.
3. Harden the SSH daemon
Create an included config instead of rewriting the vendor file:
Changing the SSH port
A non-default port reduces log noise, not the need for key authentication. If you change it, allow the new port in the cloud firewall and UFW before reloading SSH.
4. Apply a default-deny firewall
Cloud firewalls and host firewalls solve different problems; use both when available.
Do not expose database ports such as 5432, 3306, 6379, or 27017 to the public internet. Bind them to loopback, a private interface, or a private network.
5. Reduce brute-force noise
Fail2ban adds protection, but it does not replace SSH keys or a firewall. Check that its SSH rule reads the correct systemd journal or log for your distribution.
6. Keep security updates moving
Define how reboots are scheduled; unattended package installation does not guarantee that a new kernel is running.
Before using the server in production
- A named human identity can connect with a passphrase-protected key.
- Root and password SSH login are disabled and verified in a new session.
- Inbound traffic defaults to deny.
- Only justified public ports exist in cloud and host firewalls.
- Application and database processes run without root.
- Security updates and reboot ownership are defined.
- Provider console or recovery access was tested.
Record what you changed
Save the results of sshd -T, ufw status verbose, and ss -tulpn with the server handoff. Include the update and reboot policy. Never include private keys or secrets.