How to Secure SSH Access on an Ubuntu VPS
Your Ubuntu VPS is online, and you've received its IP address and login credentials. Before installing a website, database, or control panel, there's one thing worth checking: who can access your server through SSH?
SSH is the main way administrators connect to Linux servers. It provides an encrypted connection for running commands, transferring files, and managing software remotely.
But encryption doesn't prevent someone from signing in with stolen credentials. If your VPS accepts password-based logins, attackers can attempt to guess passwords or try credentials exposed in previous data breaches.
A few configuration changes can reduce those risks considerably.
The most important steps are to use SSH keys, restrict direct root access, disable unnecessary password authentication, and control who can reach the SSH service.
In this tutorial, you'll learn how to secure SSH on Ubuntu using OpenSSH, a separate administrator account, and Ubuntu's UFW firewall.
We'll also show you how to verify every important change before closing your existing connection.
The commands apply to standard Ubuntu 24.04 LTS and Ubuntu 26.04 LTS server installations. If you're using a customized image or hosting control panel, check its SSH management settings before making changes.
Quick summary
- Update Ubuntu and OpenSSH, then use a separate sudo administrator with a passphrase-protected SSH key.
- Verify a fresh key-only login and working sudo access before disabling password and direct root SSH login. Adapt authentication settings if you use MFA.
- Check SSH configuration syntax and effective settings, including applicable Match rules, before reloading the service.
- Allow your actual SSH port before enabling UFW, and review IPv4, IPv6, and any provider firewall rules.
- Keep the existing SSH connection and a verified recovery console available until a new login succeeds after all changes.
Why SSH Security Matters on a VPS
When you buy a VPS, you receive access to a virtual machine running on a hosting provider's infrastructure.
On a Linux VPS, SSH allows you to administer that machine from another computer.
A typical SSH connection looks like this:
ssh root@203.0.113.10
Here, root is the account name and 203.0.113.10 is the server's IP address.
SSH normally listens on TCP port 22, although administrators can configure another port.
Because a public VPS is reachable over the internet, its SSH service may receive login attempts from automated scanners.
These attempts don't automatically mean the server has been compromised. Scanning is common on publicly accessible systems.
The problem arises when an attacker finds a usable account, weak authentication method, or vulnerable service.
A successful administrative login may allow someone to modify website files, access databases, install software, or change server settings.
That makes SSH one of the first services you should review after provisioning a VPS.
Common SSH Security Risks
| Risk | Potential consequence |
|---|---|
| Weak account passwords | Unauthorized logins through guessed or stolen credentials |
| Direct root access | Immediate administrative control if the account is compromised |
| Exposed SSH port | Public access to the authentication service |
| Stolen private keys | Unauthorized access using legitimate key credentials |
| Incorrect file permissions | SSH keys may be exposed or authentication may fail |
| Outdated OpenSSH packages | Exposure to known, unpatched security vulnerabilities |
| Incorrect firewall rules | Accidental loss of administrative access |
No single change eliminates every risk.
The goal is to limit unauthorized access while preserving a reliable way for legitimate administrators to connect.
Before You Start: Protect Your Existing SSH Connection
Changing SSH settings on a remote server requires care.
If you disable password authentication before confirming your SSH key works, you might lose access to the VPS.
The same can happen if you activate a firewall that blocks your SSH port.
For this tutorial, you'll need:
- An Ubuntu VPS with SSH access.
- An existing root or sudo-enabled account.
- A terminal on your local computer.
- Access to a server console or recovery method, preferably through your VPS provider.
- Permission to change SSH and firewall settings.
We'll use these example details:
| Setting | Example |
|---|---|
| Server IP | 203.0.113.10 |
| New administrator | vpsadmin |
| SSH port | 22 |
| SSH key type | Ed25519 |
The example IP is reserved for documentation. Replace it with your real VPS address in every command. These examples assume SSH already listens on port 22. If you use another port, adjust the client, firewall, and Fail2Ban settings before applying them.
Before accepting a host key on your first connection, verify its fingerprint through a trusted provider console or another authenticated channel.
Keep your current SSH session open until you've completed the tutorial and confirmed that a completely new login works.
Do not rely on an existing session as proof that new connections are allowed.
If you're changing a production server, confirm your recovery access and take a suitable backup before modifying its authentication configuration.
Step 1: Update Ubuntu and Check OpenSSH
Start by connecting to your VPS using your existing account.
For a server that permits root login:
ssh root@203.0.113.10
If your hosting image provides a different administrator account, use that username instead.
Once connected, identify your operating system:
cat /etc/os-release
Confirm that you're running a supported Ubuntu version.
Next, update the package information:
sudo apt update
Install available updates:
sudo apt upgrade
Review the proposed changes before accepting them, especially if this is an existing production VPS.
Now check whether OpenSSH Server is installed:
apt policy openssh-server
This displays package information, including the installed version where available.
If OpenSSH Server isn't installed, you can install it with:
sudo apt install openssh-server
Check the SSH service:
sudo systemctl status ssh
A normally running service will report a status similar to:
Active: active (running)
Some Ubuntu installations also use systemd socket activation for SSH. You can inspect the socket with:
systemctl status ssh.socket
This distinction becomes important if you later change SSH's listening port. For now, we'll keep the existing port.
Why Updates Come First
Security fixes for OpenSSH and other Ubuntu packages are distributed through the operating system's update system.
Using an outdated SSH service may leave your VPS exposed to vulnerabilities that have already been corrected in supported package versions.
You don't need to install a newer OpenSSH build manually simply because its upstream version number is higher.
Ubuntu may backport security patches to the packaged version supplied with your release.
What matters is whether you're using a supported Ubuntu release and applying the appropriate security updates.
Step 2: Create a Dedicated SSH Administrator
Some VPS images allow administrators to sign in directly as root.
Although that provides convenient access, using a separate administrator account is generally preferable for routine work.
The root account has unrestricted system privileges. A mistake made while operating as root can modify critical files immediately.
A separate account lets you perform ordinary tasks without those privileges and request elevated access through sudo when needed.
Create the User
Run:
sudo adduser vpsadmin
Ubuntu will ask you to create a password and may request optional account details. Creating this local password does not enable SSH password login if your image already disables it; use the manual key installation method in Step 4 through your existing administrator session in that case.
Choose a strong, unique password.
The account password can still be useful for local administrative operations even after you disable SSH password authentication.
Now grant the account sudo privileges:
sudo usermod -aG sudo vpsadmin
Confirm the account's group membership:
groups vpsadmin
The result should include sudo.
If your VPS already has a suitable sudo-enabled account, you can use that account instead of creating another.
Don't disable root SSH login yet. You'll do that only after confirming that the new account can authenticate and run administrative commands.
Step 3: Generate an SSH Key Pair
SSH supports several authentication methods.
Password authentication requires the server to verify a secret supplied during login.
Public key authentication works differently.
Your computer keeps a private key, while the server stores the corresponding public key. During authentication, the SSH client proves possession of the private key without sending that private key to the server.
This is generally more resistant to remote password guessing.
Create an Ed25519 Key
Open a terminal on your own computer.
On Windows, you can use PowerShell or Windows Terminal. Linux and macOS users can use their normal terminal applications.
Run:
ssh-keygen -t ed25519 -C "ubuntu-vps-admin"
The command generates an Ed25519 key pair.
When prompted for a filename, you can accept the default if you don't already have a key stored there.
A typical location is:
~/.ssh/id_ed25519
If a key already exists, choose a different filename instead of overwriting it.
Next, enter a passphrase.
A passphrase protects your private key if someone obtains the file from your computer.
After completing the process, you'll have two files.
| File | Purpose |
|---|---|
id_ed25519 | Private key stored on your computer |
id_ed25519.pub | Public key authorized on the server |
Never upload your private key to the VPS or share it with another person.
Only the public key belongs on the server.
For administrators managing several VPS instances, separate SSH keys can also make it easier to revoke access to an individual environment.
Step 4: Add Your Public Key to Ubuntu
Now your VPS needs to recognize the public key you generated.
The simplest method on Linux or macOS, when available, is ssh-copy-id.
From your local computer, run:
ssh-copy-id -i ~/.ssh/id_ed25519.pub vpsadmin@203.0.113.10
Enter the vpsadmin account password if requested.
This installs your public key in the account's SSH authorization file:
/home/vpsadmin/.ssh/authorized_keys
If ssh-copy-id isn't available, you can install the key manually.
Alternative: Install the Public Key Manually
First, display your public key on your local computer.
On Linux or macOS:
cat ~/.ssh/id_ed25519.pub
On Windows PowerShell, using the default key path:
Get-Content "$env:USERPROFILE\.ssh\id_ed25519.pub"
Copy the complete public key.
Return to your existing VPS administrator session.
Create a secure SSH directory for the new user:
sudo install -d -m 700 -o vpsadmin -g vpsadmin /home/vpsadmin/.ssh
Open the authorization file:
sudo nano /home/vpsadmin/.ssh/authorized_keys
Paste the public key on one line, save the file, and exit.
Then set the correct ownership and permissions:
sudo chown vpsadmin:vpsadmin /home/vpsadmin/.ssh/authorized_keys
sudo chmod 600 /home/vpsadmin/.ssh/authorized_keys
The SSH directory should normally have permission mode 700, while the authorized_keys file should use 600.
These settings restrict unauthorized modification of the account's SSH authorization data.
Verify SSH Key Login
Open a second terminal on your computer.
Run:
ssh -i ~/.ssh/id_ed25519 vpsadmin@203.0.113.10
Use the actual key filename if you chose a different one.
You may be asked for your private key's passphrase.
After connecting, confirm that the account can use sudo:
sudo whoami
The expected output is:
root
If this command succeeds, your new administrator has working SSH access and administrative privileges.
There's one more test worth performing.
Confirm That SSH Really Uses Your Key
SSH clients can sometimes reuse an existing connection or try several configured authentication methods.
To test a fresh key-only connection, run this command on your local computer:
ssh -S none \
-o IdentitiesOnly=yes \
-o PreferredAuthentications=publickey \
-o PasswordAuthentication=no \
-o KbdInteractiveAuthentication=no \
-i ~/.ssh/id_ed25519 \
vpsadmin@203.0.113.10
On Windows PowerShell, enter the same options on a single line if you aren't using PowerShell's line-continuation syntax.
This connection explicitly requires public key authentication and avoids reusing a shared SSH connection.
If it succeeds, you've verified the authentication method you'll rely on after disabling password logins.
Do not continue if this test fails.
Step 5: Disable Root Login and SSH Password Authentication
With a verified administrator account and working SSH key, you can change the server's authentication settings.
Ubuntu commonly stores OpenSSH configuration in two locations:
/etc/ssh/sshd_config
And:
/etc/ssh/sshd_config.d/
The second directory contains separate configuration files that can be included by the main OpenSSH configuration.
Using a dedicated configuration file makes your changes easier to identify and maintain.
Back Up the Current Configuration
Before editing, create a dated backup of the SSH configuration directory in root-only storage:
sudo cp -a /etc/ssh "/root/ssh-backup-$(date +%Y%m%d-%H%M%S)"
This preserves the main configuration and its included snippets. Keep the backup private: it also contains the server's private host keys. Review any existing 00-vps-hardening.conf before editing it; a backup does not replace a working recovery console.
Create a Hardening Configuration
Run:
sudo nano /etc/ssh/sshd_config.d/00-vps-hardening.conf
Add these directives:
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
MaxAuthTries 3
Save the file.
Here's what you're changing:
| Directive | Effect |
|---|---|
PubkeyAuthentication yes | Allows public key authentication |
PasswordAuthentication no | Disables ordinary SSH password logins |
KbdInteractiveAuthentication no | Disables keyboard-interactive authentication |
PermitRootLogin no | Blocks direct SSH access to the root account |
MaxAuthTries 3 | Limits failed authentication attempts within a connection |
The keyboard-interactive setting is appropriate for this key-only tutorial. If your organization uses an SSH multi-factor authentication system that depends on keyboard-interactive authentication, its configuration must be handled differently.
Check for Conflicting SSH Settings
On Ubuntu, the main SSH configuration commonly includes files from sshd_config.d near the beginning.
As Ubuntu's OpenSSH documentation explains, OpenSSH generally uses the first applicable value it encounters for most directives. The OpenSSH configuration manual describes the individual settings.
That means a setting in another configuration file may take precedence over one you add later.
The 00- prefix helps your configuration load early, but it doesn't guarantee that another earlier file or conditional setting won't affect the result.
Don't assume the file is working simply because it contains the correct text.
You need to check the effective configuration.
Test the Configuration Before Applying It
Run:
sudo sshd -t
This checks OpenSSH configuration syntax.
If the command returns successfully without output, the syntax check has passed.
Next, display the effective authentication settings:
sudo sshd -T | grep -E '^(pubkeyauthentication|passwordauthentication|kbdinteractiveauthentication|permitrootlogin|maxauthtries) '
For this setup, the values should include:
pubkeyauthentication yes
passwordauthentication no
kbdinteractiveauthentication no
permitrootlogin no
maxauthtries 3
Their order may differ.
If your server uses conditional Match rules, also evaluate the intended user and connection context with OpenSSH's extended test mode:
sudo sshd -T -C user=vpsadmin,addr=198.51.100.25,host=admin.example.net,laddr=203.0.113.10,lport=22 | grep -E '^(pubkeyauthentication|passwordauthentication|kbdinteractiveauthentication|permitrootlogin|maxauthtries) '
Replace the source address and resolved source hostname with your administrator connection details, and the local address and port with those seen by SSH on the server. Repeat the check for other permitted administrators and for user=root to confirm direct root access remains disabled. If any effective value differs from the intended policy, resolve the conflicting configuration before reloading.
A syntax check alone cannot confirm that every authentication rule has the intended effect.
Reload the SSH Service
Once the configuration passes validation, reload the active SSH service:
sudo systemctl reload ssh
If your image uses a different service arrangement, inspect ssh.service and ssh.socket before applying the change.
Don't close your existing administrator session.
Instead, open another terminal and repeat the key-only login test from Step 4.
Then confirm that sudo whoami still returns root.
Only after those checks succeed should you consider your new login configuration ready.
Step 6: Configure the UFW Firewall
SSH keys protect authentication, but they don't determine which networks can reach the SSH service.
For additional protection, use a firewall.
Ubuntu provides UFW, which lets you manage common firewall rules without writing low-level packet filtering rules manually.
Check Whether UFW Is Active
Run:
sudo ufw status verbose
If UFW isn't installed, install it first:
sudo apt install ufw
Before enabling it, allow the SSH port you currently use.
For the default port:
sudo ufw allow 22/tcp
If you host a public website on this VPS, you may also need:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
These allow HTTP and HTTPS traffic.
Now set the default incoming policy:
sudo ufw default deny incoming
Review the configured rules:
sudo ufw show added
Review all required services, including control-panel, mail, VPN, or application ports on an existing server, and allow their intended traffic before enabling the firewall. Keeping an established SSH session open does not prove that a new connection is permitted.
Once you've confirmed that the saved rules permit new connections to your actual SSH port, enable UFW:
sudo ufw enable
Check the result:
sudo ufw status numbered
Open another SSH connection and confirm that it works.
If your provider operates an additional cloud firewall, verify its rules separately.
Restrict SSH to a Specific IP Address
If you manage the VPS from an office with a fixed public IP, you can restrict SSH to that address.
For example:
sudo ufw allow from 198.51.100.25 to any port 22 proto tcp
Replace 198.51.100.25 with your trusted public IP.
An IP allowlist only restricts access when your firewall's overall rules enforce it.
If a broad rule still allows SSH from anywhere, adding a restricted rule doesn't cancel that broader permission. By itself, the restricted rule does not block other addresses. Review IPv4 and IPv6 rules separately, including any broad OpenSSH application-profile rules. Follow Ubuntu's firewall guide when reviewing or removing rules.
Before removing general access rules, test connectivity from your trusted address and make sure an emergency recovery method is available.
If your IP changes frequently, an allowlist may be inconvenient. A suitably configured private VPN is another option for restricting administrative access.
Important for Docker users: Docker can publish container ports through firewall rules that don't behave as expected under UFW. Review Docker's firewall and UFW documentation separately if your VPS runs containers.
Step 7: Check SSH Login Attempts and Enable Additional Protection
Your server is now configured to accept SSH keys instead of ordinary passwords.
That removes an important password-guessing attack path, but it doesn't mean automated connections will stop.
You can monitor login attempts using Ubuntu's system logs.
Review Recent SSH Authentication Events
Run:
sudo journalctl -u ssh --since "24 hours ago"
This displays recent records associated with the SSH service.
To monitor new events as they arrive:
sudo journalctl -u ssh -f
Watch for unexpected successful logins, repeated authentication failures, and unusual account activity.
A server receiving unsuccessful login attempts isn't necessarily compromised.
The more important question is whether an unauthorized login succeeded or another security control failed.
Should You Install Fail2Ban?
Fail2Ban is a tool that monitors selected log events and can temporarily block IP addresses associated with repeated failures.
It's useful in some environments, although it is not a substitute for SSH keys and firewall restrictions.
Install it with:
sudo apt install fail2ban
For Ubuntu systems using systemd journal logging, a basic SSH jail configuration can be created at the following path. Edit this file with sudo nano, preserving any existing local settings:
/etc/fail2ban/jail.d/sshd.local
For example:
[sshd]
enabled = true
backend = systemd
maxretry = 5
findtime = 10m
bantime = 1h
Before activating this configuration, confirm that the SSH filter and firewall ban action are compatible with your server. With backend = systemd, the filter uses journal matching rather than a file logpath; see the Fail2Ban configuration reference. If SSH uses a nonstandard port, configure the jail's port accordingly.
Test the Fail2Ban configuration:
sudo fail2ban-client -t
If validation succeeds, restart the service:
sudo systemctl restart fail2ban
Check the SSH jail:
sudo fail2ban-client status sshd
This should report the jail's status and available failure and ban statistics.
Remember that repeated mistakes while connecting can also trigger a ban against your own IP address.
For a small VPS using SSH keys and well-restricted network access, Fail2Ban is an optional additional control.
Step 8: Maintain SSH Security After Setup
SSH hardening doesn't end when the configuration is saved.
Over time, you may add administrators, install new software, change firewall rules, or connect automated deployment systems.
Those changes can affect your server's security.
Keep OpenSSH Updated
Ubuntu provides automatic security update facilities through unattended-upgrades.
Check whether the package is installed:
apt policy unattended-upgrades
If necessary:
sudo apt install unattended-upgrades
Review the configured update schedule:
cat /etc/apt/apt.conf.d/20auto-upgrades
Ubuntu commonly uses the following daily update settings:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
If that file is missing, review the package configuration rather than assuming automatic updates are enabled. Check the APT timers and simulate an unattended upgrade:
systemctl list-timers 'apt-daily*'
sudo unattended-upgrade --dry-run --debug
Review the allowed origins and scheduling described in Ubuntu's automatic updates guide. Don't assume every third-party package or manually installed application is covered by these settings.
Some updates may also require a reboot or service restart.
Remove Old Authorized Keys
If someone no longer needs server access, remove their public key from the relevant account's authorized_keys file.
You can inspect the administrator's authorized keys with:
sudo cat /home/vpsadmin/.ssh/authorized_keys
Identify each key before deleting it.
Removing the wrong key could prevent an administrator's next login or break an automated deployment process. Removing an authorized key does not terminate sessions that are already open.
If several people administer the same VPS, individual user accounts and separate keys make access management easier.
Protect Your Private Keys
Your SSH private key is an important credential.
Keep it on a trusted device, protected by a passphrase and suitable operating system permissions.
Avoid storing it in public repositories, shared folders, or unprotected backup archives.
If a private key is lost or suspected to be compromised, generate a replacement and update the affected server's authorized keys.
Verify Your Recovery Method
You should know how to regain access if your laptop fails, your key becomes unavailable, or a firewall rule blocks your connection.
Depending on your VPS provider, recovery might involve a web-based console, rescue environment, or reinstall procedure.
Check these capabilities before an incident rather than assuming they're always available.
Should You Change the Default SSH Port?
Changing SSH from port 22 to another port is frequently recommended as a security improvement.
It can reduce unwanted connections from scanners that only check default ports.
However, it doesn't stop a determined attacker from discovering the SSH service.
A port scanner can still identify an SSH listener on a different port.
Changing ports also adds configuration work.
You'll need to coordinate:
- OpenSSH listener settings.
- Ubuntu firewall rules.
- Any provider-level firewall.
- SSH client configuration.
- Automated deployment and backup connections.
On Ubuntu installations using systemd SSH socket activation, the effective listening configuration may involve ssh.socket as well as OpenSSH configuration files.
Changing only Port in sshd_config may not be sufficient.
For most VPS users, properly configured SSH keys, restricted access, and security updates are more important than moving SSH to another port.
Keep port 22 unless you have a specific reason to change it.
Is Two-Factor Authentication Necessary for SSH?
Multi-factor authentication can provide additional protection for administrative access.
OpenSSH supports security-key-based authentication using compatible FIDO hardware authenticators, along with other authentication arrangements.
For a personal development VPS, a strongly protected Ed25519 key may meet your requirements.
For business infrastructure managed by several administrators, hardware-backed credentials or an appropriate MFA system may be worth considering.
Be careful when combining MFA with the settings in this tutorial.
Some SSH MFA methods require keyboard-interactive authentication, which we've disabled for the basic key-only configuration.
If you decide to deploy such a system, follow the instructions for that authentication method and verify the entire login process before enforcing it.
Don't simply enable or disable authentication directives without understanding how they interact.
How to Verify Your SSH Hardening Configuration
Before considering the setup complete, run a final review.
| Security check | Expected result |
|---|---|
| Ubuntu updates | Available security patches installed |
| Administrator account | Separate account with working sudo access |
| SSH keys | Fresh public-key login succeeds |
| Password authentication | Disabled |
| Direct root SSH login | Disabled |
| OpenSSH configuration | Passes sshd -t |
| Effective authentication settings | Match intended policy |
| UFW firewall | Permits required ports only |
| SSH logs | Accessible for investigation |
| Fail2Ban | Verified if installed |
| Recovery access | Confirmed and documented |
To inspect your effective SSH configuration:
sudo sshd -T | grep -E '^(pubkeyauthentication|passwordauthentication|kbdinteractiveauthentication|permitrootlogin) '
For the setup described here, the expected values are:
pubkeyauthentication yes
passwordauthentication no
kbdinteractiveauthentication no
permitrootlogin no
Inspect any conditional Match rules separately.
Finally, open a fresh SSH session from your local computer and confirm that your administrator can still log in and use sudo.
Your original session can then be closed.
Common SSH Errors and How to Fix Them
Even a small configuration mistake can prevent SSH access. Most problems fall into a few categories.
Permission Denied (publickey)
This error means your public-key authentication attempt wasn't accepted.
Check the username, selected private key, server-side public key, and file permissions.
You can use verbose client logging:
ssh -v -i ~/.ssh/id_ed25519 vpsadmin@203.0.113.10
This displays which authentication methods and keys the client attempts to use.
If you changed the key filename, make sure the command points to the correct file.
Connection Timed Out
A timeout often indicates a network reachability or filtering problem.
Check that you're connecting to the correct IP and port.
Review both UFW and your hosting provider's firewall.
If you can access the server through its recovery console, check the SSH listener:
sudo ss -ltnp
Verify that the service is listening on the expected address and port.
Connection Refused
A refused connection can indicate that no service is accepting connections on the requested port, or that an intermediate network control is actively rejecting the connection.
Check:
sudo systemctl status ssh
Also review:
systemctl status ssh.socket
The service configuration may differ depending on the Ubuntu image.
SSH Stops Accepting New Logins After an Edit
If you still have an active administrator session, don't close it.
Check the configuration:
sudo sshd -t
Then review the logs:
sudo journalctl -u ssh -n 50
Correct the reported problem and verify the effective settings before reloading SSH.
If every SSH connection has been lost, use your provider's verified recovery method.
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED
This warning means the server's presented SSH host key differs from the one your computer previously trusted.
A legitimate server reinstall or host key rotation can cause this, but an interception attempt is another possibility.
Don't automatically remove the old host key and accept the replacement.
First verify the new fingerprint through a trusted provider console or another authenticated channel.
Once you've confirmed that the change is legitimate, update the saved host key on your computer.
Final Thoughts
Securing SSH on an Ubuntu VPS comes down to controlling who can connect and which credentials they must use.
Start by updating OpenSSH and creating a separate administrator account. Generate a protected SSH key, verify that it works, and only then disable unnecessary password and root authentication.
Use UFW to restrict network access, review authentication logs, and keep your system updated.
You don't need to change every OpenSSH default or install every available security utility.
A simple configuration that's properly understood and regularly maintained is more useful than a complicated setup that nobody knows how to recover.
The most important rule is to test a new connection before closing the old one.
That one habit can prevent a security improvement from turning into an unnecessary server outage.
If you're setting up a new Linux server, explore AwakeHost VPS hosting to compare available configurations and deployment locations. Our managed vs unmanaged VPS guide explains how to check who is responsible for administration.
For a broader server-hardening checklist, read 10 Essential Security Steps After Buying a VPS. Once access is secured, follow our guide to hosting multiple websites on one VPS for the next setup steps.
Frequently Asked Questions
How do I secure SSH on Ubuntu?
Configure a separate sudo-enabled administrator, use SSH key authentication, disable unnecessary password and root logins, restrict network access with a firewall, and keep OpenSSH updated. Verify every change before closing your existing session.
Is SSH secure by default on Ubuntu?
OpenSSH uses encrypted connections and supports secure authentication methods. However, the effective security of your VPS depends on its configuration, account permissions, updates, and network exposure. Review those settings after deployment.
Is SSH key authentication better than passwords?
For administrative access, properly protected SSH keys generally provide stronger protection against remote password-guessing attacks. Private keys still need to be protected against theft, and unnecessary authorized keys should be removed.
Should I disable root SSH login?
For ordinary administration, disabling direct root SSH login is a sensible measure once you have another working administrator account with sudo privileges. Verify the replacement account before making the change.
Should I change SSH port 22?
Not necessarily. Changing the port may reduce basic scanning noise but doesn't prevent discovery of the SSH service. Strong authentication, firewall restrictions, and security updates provide more meaningful protection.
Is Fail2Ban required if SSH passwords are disabled?
No. Fail2Ban can help limit repeated connection attempts, but properly configured SSH keys and network restrictions already address important authentication risks. Its value depends on your environment.
Can I configure SSH keys using Windows?
Yes. Windows 10 and Windows 11 include OpenSSH capabilities that can be used through PowerShell or Windows Terminal. You can generate Ed25519 keys and use them to authenticate to an Ubuntu VPS.
What happens if I lose my SSH private key?
You may lose the ability to authenticate if no other authorized credentials are available. Recovery may be possible through a provider console or another previously configured access method. Maintain a secure recovery plan before disabling alternative authentication.
Can I use the same SSH key for multiple VPS servers?
Yes, OpenSSH supports using one key for multiple servers. However, separate keys can make revocation and access management easier, particularly when servers belong to different customers, teams, or security environments.
Does disabling SSH passwords affect sudo?
Not by itself. Disabling SSH password authentication controls remote SSH login methods. A sudo-enabled user may still need to enter their local account password when running administrative commands.