Enable SSH on Ubuntu Server (Short Answer)
Four commands enable SSH on every current Ubuntu Server release: sudo apt update, sudo apt install openssh-server, sudo systemctl enable --now ssh, sudo ufw allow ssh. The complication is that Ubuntu now starts SSH through systemd socket activation (introduced in 22.10, so 24.04 is the first LTS with it, and 26.04 keeps it), so on a stock 24.04 or 26.04 install systemctl status ssh can report inactive (dead) until the first connection after boot even though SSH is working (the third command above makes ssh.service start at boot, which ends that). Changing the port is different too: on 24.04 and 26.04 a new Port only takes effect after sudo systemctl daemon-reload and sudo systemctl restart ssh.socket. Those two changes are why most older tutorials appear to fail.
Tested on: the official Ubuntu Server cloud images for 26.04.1 LTS (OpenSSH 10.2p1, package 1:10.2p1-2ubuntu3.8), 24.04.5 LTS (OpenSSH 9.6p1, 1:9.6p1-3ubuntu13.20) and 22.04.5 LTS (OpenSSH 8.9p1, 1:8.9p1-3ubuntu0.18), in the ReadTheManual lab on 15 November 2026. Every command in the quick path, including a reboot afterwards, and every port-change step was run on all three. The first set of 24.04 screenshots is from an earlier lab run on 28 October 2026. An install from the Ubuntu Server ISO was not run, so what this page says about ISO installs follows the OpenSSH and Ubuntu documentation rather than a test.
If you ran sudo apt install openssh-server on Ubuntu 24.04 and SSH still did not seem to work, this is the post for you. Ubuntu 24.04 changed how SSH starts in a way that almost every existing tutorial gets wrong, and the symptoms look identical to a broken install.
This guide covers the full setup across Ubuntu 22.04 LTS, 24.04 LTS and 26.04 LTS, including the differences between them, the firewall step everyone forgets, and the errors that account for nearly every “I followed a guide and it did not work” thread on Ask Ubuntu.
Quick path: the four commands that work on every Ubuntu version
If you just want SSH running and you already know your way around a server, this is the minimum:
sudo apt update
sudo apt install openssh-server
sudo systemctl enable --now ssh
sudo ufw allow ssh
Verify it is running:
sudo systemctl status ssh
If you see Active: active (running) or Active: active (listening), you are done. SSH is reachable on port 22 from anywhere your firewall allows. (active (listening) is a socket that is waiting for its first connection; once a connection has started sshd, the socket reads active (running) too. Both mean SSH works.)
The third command is safe on all three releases. In the lab, sudo systemctl enable --now ssh on 26.04, 24.04 and 22.04 printed only the SysV-sync lines and, on 24.04 and 26.04, two Created symlink lines; it did not error because of ssh.socket. After a reboot SSH was listening on port 22 on all three. On 24.04 and 26.04 ssh.service now starts at boot and serves the port that ssh.socket opens; on 22.04 ssh.service listens on its own.

sudo systemctl enable --now ssh runs without error, and both ssh and ssh.socket report enabled and active.
ssh.service is now enabled, sshd started at boot on the socket’s listener, which is why the socket reads active (running).If you are new to Ubuntu Server administration, or you are on 24.04 and the steps above did not behave as expected, keep reading.
Why your tutorial probably did not work on Ubuntu 24.04
Since Ubuntu 22.10, and so on every LTS from 24.04 onwards (26.04 included), OpenSSH ships with socket activation enabled by default (Ubuntu 24.04 LTS release notes). Instead of ssh.service running constantly, systemd watches port 22 via ssh.socket. When a connection arrives, systemd starts ssh.service on demand.
For everyday use this is invisible: SSH still answers on port 22, ssh user@host still works, and once the first connection has started ssh.service it stays running. The visible differences are what systemctl status ssh shows before that first connection, and how you change the port (covered below).
Why it breaks tutorials
Older tutorials tell you to do things like this:
sudo systemctl restart ssh.service # on 24.04+ this does NOT apply a Port change
sudo systemctl status ssh # shows "inactive (dead)" until the first connection since boot
On 24.04 these can leave you convinced SSH is not running when it is. The fix is to think in terms of either the socket or the service, depending on what you are doing:
| Action | 22.04 | 24.04 and newer |
|---|---|---|
| Start SSH listening | systemctl start ssh |
systemctl start ssh.socket |
| Stop SSH listening | systemctl stop ssh |
systemctl stop ssh.socket |
Restart after editing sshd_config (any setting except Port or ListenAddress) |
systemctl restart ssh |
systemctl restart ssh.service |
Apply a changed Port or ListenAddress |
systemctl restart ssh |
systemctl daemon-reload then systemctl restart ssh.socket |
| Check if it is listening | systemctl status ssh |
systemctl status ssh.socket |
| Disable SSH entirely | systemctl disable --now ssh |
systemctl disable --now ssh.socket ssh.service |
The shorthand ssh (no suffix) means ssh.service. On 22.04 that is the whole story. On 24.04 and 26.04 the package has already enabled ssh.socket, and systemctl enable --now ssh additionally sets ssh.service to start at boot, so sshd runs all the time instead of on demand (the screenshot above shows both units enabled after a reboot). SSH works either way, which is why the four-command Quick Path above is version-agnostic. If you would rather keep the on-demand behaviour on 24.04 and later, use sudo systemctl enable --now ssh.socket instead.
Quick check on your version:
lsb_release -dstells you which Ubuntu you’re on. Of the LTS releases, 24.04 and 26.04 use socket activation; 22.04 and older use the classic service model.
Changing the SSH port on 24.04 and 26.04
With socket activation, ssh.socket owns the listening port, not sshd. A systemd generator reads Port and ListenAddress from /etc/ssh/sshd_config (and any file in /etc/ssh/sshd_config.d/) to configure the socket, as the 24.04 release notes describe, and it only does so when systemd reloads. Edit the port and restart ssh.service, and SSH is still listening on 22 (the first screenshot below shows exactly that). The fix is systemctl daemon-reload, then systemctl restart ssh.socket.
The safe order, so you cannot lock yourself out:
# 1. Set the new port (for example Port 2222) and check the file parses
sudo nano /etc/ssh/sshd_config
sudo sshd -t
# 2. Open the new port in the firewall BEFORE moving to it
sudo ufw allow 2222/tcp
# 3. Regenerate the socket configuration and restart the listener
sudo systemctl daemon-reload
sudo systemctl restart ssh.socket
# 4. Confirm what is listening now
sudo ss -tlnp | grep -E ':(22|2222)\b'



Port 2222 added and only ssh.service restarted, the listener is still on port 22 alone.
systemctl daemon-reload and systemctl restart ssh.socket, ports 22 and 2222 are both open.Your current session survives the restart. From a second terminal, connect with ssh -p 2222 user@host. Only when that works, remove the old rule with sudo ufw delete allow ssh (or sudo ufw delete allow 22/tcp if that is how you added it). On 22.04 the classic sudo systemctl restart ssh applies a port change on its own; steps 1, 2 and the second-terminal test still apply.

ssh.service is enough here, and sshd listens on 22 and 2222.Do not copy the 24.04 and later socket steps onto 22.04. In the lab, systemctl restart ssh.socket on 22.04 started the unused socket, which took over port 22 and left nothing serving 2222: a login to port 2222 was then refused.

systemctl restart ssh.socket: only port 22 is listening and port 2222 has gone. On 22.04, use ssh.service.
Step-by-step setup (verbose path)
If you’ve not set up SSH on Ubuntu before, here’s the version with explanations.
1. Update package lists
sudo apt update
This pulls the latest package information from Ubuntu’s archive servers. Without it, you might install an outdated openssh-server that has known security fixes available.
2. Install OpenSSH server
sudo apt install openssh-server
The openssh-server package gives you the sshd daemon (which accepts incoming connections) and a default /etc/ssh/sshd_config configuration file. Ubuntu Server has it if you ticked “Install OpenSSH server” in the installer, and Ubuntu cloud images ship with it; Ubuntu Desktop does not install it by default.

The package install will also install openssh-client if it isn’t already present, which gives you the ssh, scp, and sftp commands for outbound connections.
3. Verify the service is running
sudo systemctl status ssh
What you want to see depends on your version:
On 22.04:
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since [date]
On 24.04 and newer, check the socket instead with sudo systemctl status ssh.socket (plain status ssh shows ssh.service, which is inactive (dead) until the first connection, and that is normal):
● ssh.socket - OpenBSD Secure Shell server socket
Loaded: loaded (/usr/lib/systemd/system/ssh.socket; enabled; preset: enabled)
Active: active (listening) since [date]
active (listening) means the socket is open and waiting, and sshd has not been started yet. Once any connection has started sshd, the same socket reads active (running), as it does in the screenshots below, because the lab’s own SSH session had already started it. Either output means SSH is reachable. If ssh.service on 22.04, or ssh.socket on 24.04 and later, says inactive, run:
sudo systemctl enable --now ssh
This enables SSH to start at boot and starts it now, regardless of which activation method your version uses.

ssh.socket is enabled and listening on port 22; ssh.service is running but shows disabled, because the socket started it. This is the stock 26.04 state that enable --now ssh then changes.
ssh.service is enabled and running, and ssh.socket is disabled and inactive. 22.04 uses the classic service model.
4. Configure the firewall
If you have ufw enabled (Ubuntu’s default firewall front-end), you need to explicitly allow SSH or all your inbound connections will be blocked.
sudo ufw allow ssh
sudo ufw enable
ufw allow ssh adds a rule for TCP port 22. ufw enable activates the firewall if it isn’t already on. If ufw was already enabled and you skipped the allow ssh step before turning it on, you’ll lock yourself out the moment your current session ends.

If you are remote (e.g. SSH’d in from another machine to set up SSH): the order matters. Run
ufw allow sshBEFOREufw enable. Otherwise the next command can drop your existing session.
Verify your rules:
sudo ufw status
You should see 22/tcp ALLOW Anywhere in the output.
5. Find your IP address
hostname -I

This prints all the machine’s IP addresses on one line, separated by spaces. The first is usually the LAN IP you want (e.g. 192.0.2.50). On most cloud VMs the public address is mapped by the provider and does not appear here; find it in the provider’s console or with curl ifconfig.me.
6. Connect from another machine
From a Linux or macOS terminal:
ssh [email protected]
Replace username with your Ubuntu account username (run whoami on the Ubuntu server if you don’t know it) and the IP with what hostname -I reported.
The first time you connect, SSH asks you to verify the server’s host key:
The authenticity of host '192.0.2.50' can't be established.
ED25519 key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no)?

Type yes. The fingerprint is saved to ~/.ssh/known_hosts on the client; on subsequent connections SSH verifies the server is the same one and warns you if the key has changed (which usually means you re-installed the OS or someone is doing something nefarious).
What happens next depends on how the server was built. On an install from the Ubuntu Server ISO, password login is typically still allowed, so you are prompted for your Ubuntu user’s password and then get a shell. The exception is when you imported SSH keys during the install: the installer then turns password login off by default (the allow-pw setting in the Ubuntu installer reference). On an Ubuntu cloud image, and on most cloud VMs built from one, password login is switched off: there is no password prompt, and you log in with the SSH key you gave the provider or added through cloud-init. Check which you have with sudo sshd -T | grep -i passwordauthentication on the server (the next section shows how).
Password or key: what your server allows
OpenSSH’s own default is PasswordAuthentication yes (sshd_config manual), and a server with no override allows passwords. Ubuntu cloud images do override it. The image ships /etc/ssh/sshd_config.d/60-cloudimg-settings.conf containing PasswordAuthentication no, and cloud-init can add its own file such as 50-cloud-init.conf with the same setting. In the lab, sshd -T reported passwordauthentication no on the stock 26.04.1 cloud image, and both files were present on 22.04.5, 24.04.5 and 26.04.1. (The lab’s own cloud-init configuration also sets ssh_pwauth: false, which is where the 50-cloud-init.conf file in these screenshots comes from; the 60-cloudimg-settings.conf file is the image’s own.)

60-cloudimg-settings.conf (from the image) and 50-cloud-init.conf (from the lab’s cloud-init) both set PasswordAuthentication no, and sshd -T reports no.The trap is that editing /etc/ssh/sshd_config alone does not turn passwords back on. That file includes /etc/ssh/sshd_config.d/*.conf near the top, and sshd uses the first value it reads for a setting, so the drop-in wins. Ubuntu’s OpenSSH server documentation says settings in files under sshd_config.d/ override the main file, and the sshd_config manual says “for each keyword, the first obtained value will be used”. The lab shows it:

PasswordAuthentication yes appended to /etc/ssh/sshd_config, but sshd -T still reports no because the drop-ins are read first.To allow passwords on such a server, change the value in every drop-in that sets it (or add an earlier-sorting file such as 00-passwords.conf containing PasswordAuthentication yes), run sudo sshd -t, then sudo systemctl restart ssh.service. Keys are the better answer: see the key-authentication guide linked below. With no drop-ins at all, as on a server where nobody has added one, sshd falls back to its default:

sshd -T reports yes. This is a simulation of a server without the cloud files, not an ISO install.Connect from each major OS
Linux / macOS
OpenSSH client is pre-installed on every modern Linux distribution and on macOS. Just use ssh username@host from a terminal.
Windows 10 and 11
Windows 10 (build 1809 or newer) and Windows 11 ship with OpenSSH client pre-installed. From PowerShell or Command Prompt:
ssh [email protected]
If Windows says ssh is not recognised, install OpenSSH Client via Settings -> Apps -> Optional features -> Add a feature -> OpenSSH Client.
Older Windows or environments without OpenSSH
PuTTY is the long-standing alternative. Download, run, enter the IP and port 22, click Open. It uses a different key format: if you generated keys for OpenSSH later, use puttygen to convert.
Phones / tablets
Termius, Blink Shell (iOS), JuiceSSH (Android). Useful for emergency reboots from the pub.
Five errors that account for almost every SSH problem
If your SSH setup isn’t working, one of these is almost certainly the cause.
“Connection refused”
The server is reachable on the network but nothing is listening on the port you’re hitting.

- Check the service is actually running:
sudo systemctl status sshon the server. - On 24.04+, check the socket specifically:
sudo systemctl status ssh.socket. - Verify SSH is listening on port 22:
sudo ss -tnlp | grep :22. - If you changed the port in
/etc/ssh/sshd_config, are you connecting to the new port? Usessh -p 2222 user@hostto specify a non-default port. - On 24.04 and 26.04, if
ssstill shows the old port after you changedPort, the socket was never told: runsudo systemctl daemon-reloadthensudo systemctl restart ssh.socket.
“Connection timed out”
The packet isn’t reaching the server. Almost always a firewall issue.
- Did you run
sudo ufw allow ssh? - Is there an upstream firewall between you and the server (router, cloud provider security group, ISP block on inbound 22)?
- For cloud VMs: check the cloud provider’s security group / network ACL allows port 22 from your IP.
“Permission denied (publickey)”
The server only accepts SSH key authentication and your key isn’t being offered or accepted.
- Ubuntu cloud images, and most cloud VMs, ship with password login off, so this error is the normal first result of trying a password there. ISO installs usually allow passwords. Check with
sudo sshd -T | grep -i passwordauthenticationand look in/etc/ssh/sshd_config.d/, not onlysshd_config(see Password or key above). - On the client, ensure your key is in
~/.ssh/and named correctly (id_ed25519orid_rsa). - Run with
ssh -v user@hostto see exactly which keys are being tried.
The companion guide on SSH key authentication covers key generation, permissions, and the ~/.ssh/authorized_keys file in depth.
“Host key verification failed”
The server’s identity has changed since the last time you connected.
- Most innocent explanation: the server was rebuilt or reinstalled, so its host key changed.
- Less innocent: someone is doing a man-in-the-middle attack.
- To clear the old key for a known IP:
ssh-keygen -R 192.0.2.50then reconnect. - Verify the new host key fingerprint matches what the server actually has before accepting.
“Connection reset by peer”
The TCP connection was established and then immediately killed. Usually a server-side issue.
- A common cause:
fail2banbanned your IP after too many failed login attempts. Wait the configured ban time, or unban yourself from another machine:sudo fail2ban-client unban 1.2.3.4. - Less common: a misconfigured
sshd_configcausessshdto crash on connect. Checkjournalctl -u ssh.servicefor clues (on 24.04 and later,journalctl -u ssh.socketshows problems with the listener itself).
What to do next
Enabling SSH is the first step. Run any internet-facing server with default config and you’ll be picking brute-force attempts out of the logs within hours.
The follow-on tasks, in order of priority:
- Switch to SSH key authentication: much harder to brute-force than passwords. Companion guide: SSH Key Authentication on Ubuntu.
- Disable password authentication once your keys are working. This closes off the brute-force vector entirely. Covered in the SSH hardening guide.
- Add fail2ban: bans IPs that fail too many times in a row. Helpful even with key-only auth, mostly because it cleans up your logs.
- Change the SSH port: mild security-by-obscurity, mostly useful for noise reduction. Many sysadmins consider this theatre; we cover the case for and against in the hardening guide.
If you’re running this on a Raspberry Pi instead of standard Ubuntu Server, see the companion Enable SSH on Raspberry Pi guide, because the mechanics differ enough to warrant their own post.
Frequently asked questions
Does this work on Ubuntu Server vs Desktop?
Yes, identical. The difference is that Ubuntu Server installs openssh-server by default in many cases; Ubuntu Desktop usually doesn’t, so the apt install openssh-server step is required either way unless you explicitly opted in during install.
Why is SSH on port 22 by default? Should I change it?
Port 22 was assigned to SSH by IANA in 1995, when Tatu Ylönen released the first version of the protocol. Every SSH client tries port 22 unless you tell it otherwise.
Changing the port is a debated practice. The argument for: brute-force scanners hitting port 22 won’t see your service, so authentication logs stay clean. The argument against: anyone who actually wants in will scan all 65,535 ports anyway, so this is “security through obscurity.”
In practice, the noise reduction is genuinely useful. A non-standard port plus key-only auth plus fail2ban produces a server you basically never have to look at. If your only defence is “I’m on port 2222,” you have a problem.
Can I run SSH on multiple ports at once?
Yes. Edit /etc/ssh/sshd_config and add multiple Port lines:
Port 22
Port 2222
On 22.04, run sudo systemctl restart ssh. On 24.04 and 26.04, run sudo systemctl daemon-reload then sudo systemctl restart ssh.socket: ports are applied by the socket, so restarting ssh.service alone leaves the listener unchanged. Allow the new port in ufw before you rely on it.
Why do I see ssh.socket not ssh.service in 24.04?
Ubuntu has enabled systemd socket activation for SSH by default since 22.10, so 24.04 and 26.04 both use it. See “Why your tutorial probably didn’t work on Ubuntu 24.04” earlier in this guide for the full explanation.
I’m getting “permission denied”: what’s wrong?
If it says Permission denied (publickey), password auth is disabled (the default on cloud images) and your key isn’t being accepted. See the companion SSH key authentication guide.
If it says Permission denied, please try again after you enter the password, you’re typing the wrong password OR the username doesn’t exist. Run whoami on the server itself to confirm the username; remember Ubuntu is case-sensitive.
Can I SSH from my phone?
Yes. Termius, Blink Shell (iOS), and JuiceSSH (Android) all work well. Generate a key on the phone, add the public key to ~/.ssh/authorized_keys on the server, and you have a portable terminal in your pocket. Useful when something needs rebooting and you’re not at a desk.
How do I disable SSH again?
# 22.04
sudo systemctl disable --now ssh.service
# 24.04+
sudo systemctl disable --now ssh.socket ssh.service
You may also want to remove the firewall rule: sudo ufw delete allow ssh.
Is SSH safe to expose to the internet?
With default settings: not really. With key-only authentication, fail2ban, and a non-default port, it’s been the standard way to administer Linux servers since the late 1990s and remains fine in 2026. The hardening guide covers exactly what to change. Safer still is not exposing port 22 at all: put the server on a mesh VPN (the Tailscale install guide for Linux takes a few minutes) and SSH in over that.
Where you’ll meet this at work
The commands on this page are the base layer of how Linux servers are administered in most companies, but staff rarely connect straight to port 22. In Azure, Azure Bastion provides SSH to Linux VMs through the Azure portal or a native client. Microsoft Entra ID sign-in for Linux VMs replaces copied keys with OpenSSH certificate-based authentication tied to a work identity. The certificate idea itself is plain OpenSSH, described in the ssh-keygen manual.
What maps one to one: sshd, host key checks, authorised keys, the socket-versus-service behaviour above, and the firewall rule (a network security group or cloud firewall at work). What does not: the identity layer, approval and audit trail that those products put in front of sshd. A home lab has no equivalent unless you build one. Doing the manual version first is what lets you read the product’s logs and failures, because you know what it is wrapping.
This is the canonical setup guide. Companion posts cover SSH Key Authentication, SSH Hardening, Fail2ban for SSH, SCP and SFTP, SSH Tunneling, Common SSH Errors, and SSH from Windows.
If you found a gotcha not covered here, drop it in the comments. I update this post as new versions of Ubuntu and OpenSSH ship.
The Complete SSH Series
Getting connected
- Enable SSH on Ubuntu Server (you are here)
- Enable SSH on Raspberry Pi
- SSH Essentials: Remote Administration
- SSH from Windows to Ubuntu
Authentication and hardening
File transfer and tunnelling
Reference
Before you expose any of this: the seven steps that decide whether a home lab survives contact with the internet, in the order they matter, are in How to Secure a Homelab Network in 2026.
RTFM Apparel · printed in the UK

ReadTheManual is run, written and curated by Eric Lonsdale.
Eric has over 20 years of professional experience in IT infrastructure, cloud architecture, and cybersecurity, but started with PCs long before that.
He built his first machine from parts bought off tables at the local college campus, hoping they worked. He learned on BBC Micros and Atari units in the early 90s, and has built almost every PC he’s used between 1995 and now.
From helpdesk to infrastructure architect, Eric has worked across enterprise datacentres, Azure environments, and security operations. He’s managed teams, trained engineers, and spent two decades solving the problems this site teaches you to solve.
ReadTheManual exists because Eric believes the best way to learn IT is to build things, break things, and actually read the manual. Every guide on this site runs on infrastructure he owns and maintains.
Enjoyed this guide?
New articles on Linux, homelab, cloud, and automation every 2 days. No spam, unsubscribe anytime.





