Secure SSH on Ubuntu VPS: 10 Essential Hardening Steps

  • Home
  • Linux
  • Secure SSH on Ubuntu VPS: 10 Essential Hardening Steps
Secure SSH Ubuntu VPS administration on a developer workstation

Secure SSH Ubuntu VPS administration on a developer workstation
Illustrative photograph by Jefferson Santos / Unsplash.

SSH is the administrative entrance to most Linux virtual private servers. It makes remote maintenance practical, but it also exposes a sensitive service to the internet whenever its listening port is reachable. A sound SSH configuration therefore has two objectives that must be pursued together: preventing unauthorised access and preserving reliable access for legitimate administrators.

Security advice often overlooks the second objective. Instructions to disable passwords or change the SSH port can be technically correct in a particular environment yet disastrous when applied in the wrong order. This guide explains how to strengthen SSH on an Ubuntu VPS without turning the hardening process into an avoidable outage.

1. Establish a working recovery route first

Locate your VPS provider’s out-of-band console, recovery environment or equivalent access method before editing anything. Keep a current administrative session open and use a second terminal to test every authentication change. If a firewall or daemon error blocks new logins, that first session may be your only easy route to recovery.

Write down the server’s IP address, SSH port and recovery procedure. Never use a production server as the first place to experiment with unfamiliar authentication settings.

2. Check the Ubuntu release and SSH service

Start with information rather than assumptions. The following commands report the operating system, service condition and listening sockets:

cat /etc/os-release
sudo systemctl status ssh
sudo ss -tlnp | grep ssh

Ubuntu installations can differ, particularly when the provider customises the image. Some releases and configurations use systemd socket activation for SSH. Check the actual service and socket arrangement before changing listening ports; do not assume that an older tutorial’s file paths and restart sequence are universally appropriate.

3. Create a named account with controlled administrative rights

Routine administration is easier to audit when engineers have individual accounts rather than sharing root credentials. For an illustrative username, the basic Ubuntu commands are:

sudo adduser deployadmin
sudo usermod -aG sudo deployadmin

Only grant sudo rights to people whose responsibilities require them. A public application should normally run under a separate, less-privileged service account instead of an interactive administrator account. If you use automation, give it the minimum privileges needed to perform its specific tasks.

4. Generate a modern public-key pair on your own computer

Public-key authentication avoids transmitting a reusable SSH login password. On a suitably equipped client, Ed25519 is a common modern choice. Generate a key locally and protect its private component with a passphrase:

ssh-keygen -t ed25519 -C "your-device-name"

Keep the private key on the trusted device. Add only the public key to the intended account on the server, using an approved provisioning mechanism or an SSH copy method that is actually available. On Unix-like clients, the usual helper is ssh-copy-id deployadmin@SERVER_IP. Never paste the private key into a support ticket, chat message or shared document.

5. Verify the new login before withdrawing the old one

From a second terminal, connect using the new account and confirm that authorised administration works:

ssh deployadmin@SERVER_IP
sudo whoami

Replace SERVER_IP with the actual address. If sudo returns root after successful authentication, the new administrative path is functional. Also verify the login from the device and network you expect to use in normal operations. A key installed incorrectly or denied by restrictive file permissions can still leave you locked out.

6. Validate effective SSH configuration

On Ubuntu, the OpenSSH daemon configuration can include drop-in files under /etc/ssh/sshd_config.d/. Order and precedence matter. Before changing authentication settings, inspect the effective configuration and test syntax:

sudo sshd -t
sudo sshd -T | grep -E '^(passwordauthentication|permitrootlogin|pubkeyauthentication|port) '

The first command checks configuration syntax; the second displays effective values for a default connection context. Match blocks can change results for particular users or addresses, so investigate those when relevant. Consult the OpenSSH server configuration reference instead of copying incompatible snippets from old tutorials.

7. Disable password authentication only after keys work

Once public-key access is demonstrably reliable, consider disabling SSH password logins as part of a documented policy. Your setting must be placed where the daemon will actually read it, and its interaction with included files and other authentication methods must be understood. Check sshd -T again, validate the configuration and reload the SSH service only after a safe path remains open.

Root login restrictions can be valuable, but they are not a substitute for working administrative accounts. Be particularly careful on servers provisioned with root as the only usable account. Test first, change second.

8. Configure firewall access deliberately

A firewall can limit which networks are allowed to reach SSH. Where your administrative IP is stable, restricting access to that address or an approved VPN can substantially reduce exposure. If the office or home IP changes frequently, a restrictive rule may create operational problems unless an alternate route exists.

Before enabling UFW, allow the exact active SSH port. If you use the default port and Ubuntu’s standard OpenSSH application profile, sudo ufw allow OpenSSH is commonly appropriate. Our UFW firewall guide covers rule ordering and recovery in detail.

9. Review authentication logs and reduce credential exposure

Look for repeated failures, unusual login times and unexpected key changes. On systemd systems, sudo journalctl -u ssh --since "today" can help, subject to the actual service name and log configuration. Keep software patched and remove access promptly when an employee or contractor no longer requires it.

Do not assume that changing port 22 to an obscure number prevents intrusion. It may reduce automated scanning noise, but it is not equivalent to strong authentication or network restrictions. Monitoring and good key management remain essential.

10. Record and test a recovery procedure

Document how to reach the provider console, inspect daemon logs, correct a firewall rule, restore configuration files and restart the appropriate service. Keep a secure backup of approved configuration. Test a secondary administrator account or emergency-access method according to your organisation’s policy.

For a newly purchased server, work through our first-day Ubuntu VPS checklist and verify the operating-system update and backup procedures before deploying public applications. If you are selecting infrastructure, compare FyreHost VPS hosting plans according to your required resources and support scope rather than assuming that any virtual machine arrives fully hardened.

Common SSH mistakes worth avoiding

The most dangerous mistake is changing the only working authentication method without confirming its replacement. Other frequent problems include opening SSH to everyone when access could be restricted, changing the daemon’s listening port without updating firewall rules, overlooking provider-level firewalls, and editing multiple configuration files without checking the final effective settings.

An administrator may also misdiagnose a network problem as an authentication failure. “Connection refused” normally suggests that a destination is actively rejecting the connection or that nothing is listening on the target port; “permission denied” means the service was reached but authentication was unsuccessful. Different symptoms require different investigations. The next article explores the firewall layer behind many of these connection failures.

Frequently asked questions

Is SSH secure by default on Ubuntu?

OpenSSH provides a mature encrypted protocol, but the security of a deployment depends on its configuration, patch level, key management, network exposure and operational practices. Review the server’s effective settings rather than assuming every image is configured identically.

Should I change the default SSH port 22?

Changing the port can reduce background scanning noise but does not replace authentication, updates or firewall rules. It also introduces the possibility of accidental lockout, particularly with systemd socket activation or provider firewalls.

Is SSH key authentication safer than passwords?

Well-managed public-key authentication reduces reliance on reusable passwords and resists ordinary password guessing. Protect private keys with appropriate device controls and passphrases, and remove old authorised keys.

Can I disable root login immediately after provisioning?

Not safely until another administrative account has been created, tested and confirmed to work. Keep a provider-console recovery method available during the transition.

Why does SSH say connection refused?

The remote socket may not be accepting connections, or a firewall may be actively rejecting them. Verify the IP, port, daemon status, listening sockets and provider-level rules before changing authentication settings.

Does FyreHost manage SSH security for every VPS?

Management and support vary by product. Review the specific VPS offering and terms to identify which guest-operating-system tasks are included; otherwise plan to administer SSH and related security controls yourself.

Need Help?

Contact FyreHost 24/7/365 Award-Winning Support to help grow your online business!

FyreHost Help

24/7/365 Through the Chat Widget and WhatsApp

Customer Support Chat

24/7/365 Through the Chat Widget and WhatsApp

Customer Support Email

24/7/365 Through the Panel via Support Tickets

FyreHost Logo White

Get reliable hosting, domains, VPS services. Trust us to manage all your online needs from domain registration to VPS hosting.

Connect with us:

Copyright © 2026 FyreHost LTD Registered in UK with Company Number: 17242968, All Rights Reserved.