To enable incoming SSH connections on Ubuntu, install the OpenSSH Server package with sudo apt install openssh-server. Then check that TCP port 22 is listening and connect from another computer.
Ubuntu Desktop often needs the server package installed; Ubuntu Server can include it if selected during setup, and cloud images frequently come with SSH access preconfigured. Check what you already have before changing the system.
sudo apt update
sudo apt install openssh-server
sudo ss -ltnp 'sport = :22'
sudo ufw status
On Ubuntu versions using socket activation, including typical 24.04 installations, ssh.socket normally handles startup. Do not enable or reset UFW on a remote server until its SSH port is allowed and you have a recovery route. Use a separate client to finish verification.
Before you start: is SSH already installed?
Ubuntu's ssh command is the client for connecting out. Accepting incoming connections requires openssh-server, which supplies the sshd daemon. A working SSH client alone does not mean this machine accepts SSH connections.
cat /etc/os-release | grep PRETTY_NAME
dpkg -s openssh-server | grep -E 'Package:|Status:|Version:'
If the package is present, look for Status: install ok installed. If dpkg reports that the package is not installed, follow the next step. The availability of SSH depends on the image and installation choices—not only the Ubuntu version.
| Environment | What to expect | First check |
|---|---|---|
| Ubuntu Desktop | OpenSSH Server is typically absent unless you installed it. | dpkg -s openssh-server |
| Ubuntu Server | The installer can include SSH if that option was selected. | dpkg -s openssh-server |
| Ubuntu cloud image / VPS | Many images already have SSH configured by the image or provider. | Check the package, listener and provider access method before changing anything. |
Step 1: Install and enable OpenSSH Server
Open a local terminal or your provider's console on the Ubuntu machine. Install the server package from Ubuntu's repositories:
sudo apt update
sudo apt install openssh-server
These commands install the server daemon and its systemd integration. On a normal Ubuntu installation, the package generally arranges for SSH to become available without a separate enable command. However, existing configuration, image policies or deliberate overrides can change the result, so verify the listener rather than assuming setup succeeded.
dpkg -s openssh-server | grep -E 'Status:|Version:'
/usr/sbin/sshd -V 2>&1
The package status confirms installation; the daemon version command is optional. The ssh -V command refers to the client, not proof of an active SSH server.

Step 2: Verify SSH is listening on port 22
A systemd unit being installed or enabled does not prove that the network port is listening. Check the actual TCP socket:
sudo ss -ltnp 'sport = :22'
A successful result contains a LISTEN entry for :22. The owner may be systemd (when a systemd socket owns the listener) or sshd (when the service does). The local address tells you whether SSH is bound to loopback, a specific interface or all interfaces. If you deliberately configured a custom SSH port, replace 22 with the real port.
Do not confuse 127.0.0.1:22 with a listener reachable over the network. Equally, a listener on 0.0.0.0:22 is not proof that the firewall or network permits remote connections.
sudo systemctl status ssh.socket --no-pager
sudo systemctl status ssh.service --no-pager
These status checks explain how SSH is started. On the Ubuntu 24.04.5 WSL system we tested, ssh.socket displayed active (running) and ssh.service was also active; this is not a failure of socket activation. The listening-port check shows what is listening on this host. Finish with an SSH login test from the intended client.

Ubuntu 22.04 vs 24.04/26.04: ssh.service and ssh.socket
The screenshots in this guide were captured on Ubuntu 24.04 in WSL2. Ubuntu 26.04 is covered using current upstream and release documentation, not a separately reproduced 26.04 lab.
Ubuntu switched OpenSSH to systemd socket activation by default starting with Ubuntu 22.10. On new Ubuntu 24.04 and 26.04 installations, ssh.socket can listen for incoming connections while ssh.service is not running yet. The first incoming connection starts the daemon. As a result, systemctl status ssh can appear inactive without proving SSH is unavailable. Ubuntu explains the transition here.
| Ubuntu version / setup | Normal startup mode | Check |
|---|---|---|
| 20.04 and 22.04 LTS, conventional install | Persistent ssh.service | systemctl status ssh.service |
| 22.10 and later, including 24.04 and 26.04 | Systemd ssh.socket by default on new installs | systemctl status ssh.socket |
| Customized systems, upgrades, containers | May differ from version defaults | Inspect both units and the actual listener |
systemctl is-enabled ssh.socket
systemctl is-active ssh.socket
systemctl is-active ssh.service
sudo ss -ltnp 'sport = :22'
If SSH is not listening, inspect the relevant unit and logs before making changes:
sudo sshd -t
sudo journalctl -u ssh.socket -u ssh.service -b -n 40 --no-pager
On a standard new Ubuntu 24.04/26.04 socket-activated installation where the socket was disabled, sudo systemctl enable --now ssh.socket may restore it. On a system deliberately using the older persistent-service model, the corresponding unit is ssh.service. Do not enable both blindly or override custom configuration to force the table's defaults.
Ubuntu 24.04 introduced a systemd generator that reads the SSH port and listening-address settings from /etc/ssh/sshd_config and its drop-ins to generate the socket configuration. After changing those settings, a systemd daemon reload and ssh.socket restart may be required. Restarting SSH access remotely is risky: preserve your working session, allow the new port in UFW and the provider firewall, and test a second connection before closing the old one. See changing the SSH port for the full procedure.
Step 3: Allow SSH through UFW (if enabled)
Check the host firewall state first:
sudo ufw status verbose
If ufw is not installed, the command may return command not found; SSH does not require UFW. If you choose to manage the firewall with UFW, install it with sudo apt install ufw first. If UFW is inactive, its rules are not blocking SSH; you do not need to activate UFW just to install OpenSSH. If it is active, and SSH listens on the default port, inspect and add the OpenSSH application profile:
sudo ufw app info OpenSSH
sudo ufw allow OpenSSH
sudo ufw status numbered
The stock OpenSSH profile normally allows TCP 22. It does not automatically track a custom listening port. For example, if SSH really listens on 2222, permit TCP 2222 instead of assuming the profile covers it:
sudo ufw allow 2222/tcp
On an existing remote VPS, do not reset UFW or enable it with a default-deny policy without first checking all necessary access rules and confirming a recovery option. Also remember that cloud security groups or provider firewalls are separate from UFW. Read our UFW allow port guide for more detail.

Step 4: Connect from Windows, macOS or Linux
On the Ubuntu server, identify an IP address the client can actually reach. For a local-network machine, this is typically an interface address such as 192.168.x.x. For a VPS, use its assigned public or VPN address rather than copying an unrelated Docker or loopback address.
hostname -I
whoami
From a different computer, use its OpenSSH client (PowerShell on Windows, or a terminal on macOS/Linux):
ssh username@SERVER_IP
# If SSH is listening on a custom port:
ssh -p 2222 username@SERVER_IP
Replace username with an Ubuntu account name and SERVER_IP with the reachable server address. On first connection, the SSH client displays a host key fingerprint. Confirm it against a trusted fingerprint from the server before accepting the host key; on the server you can display the ED25519 host-key fingerprint with:
sudo ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
After successful authentication, run whoami, hostname and echo "$SSH_CONNECTION" to confirm you have a remote shell. A successful ss listing only proves the server listens; the separate-client login establishes end-to-end access. When testing a WSL Ubuntu instance from Windows using 127.0.0.1, that proves host-to-WSL connectivity only, not access from the Internet.

SSH still not connecting? Diagnose the actual failure
| Client symptom | What it suggests | Where to check next |
|---|---|---|
Connection refused | Nothing accepts the connection on that target, or a firewall is rejecting it. | ss, service/socket, target IP and port. Full guide. |
Connection timed out | Traffic may be dropped by UFW, a cloud firewall or another network layer. | UFW, provider rules, routing, private vs public IP. Full guide. |
Permission denied (publickey) | The SSH server was reached, but authentication failed. | Correct account, client key, server authorized_keys and configured auth methods. |
Unit ssh.socket could not be found | Package missing, older version or a custom system setup. | dpkg -s openssh-server, systemctl status ssh.service. |
| Works locally, not from another machine | Listener bound to localhost or blocked in the network path. | sudo ss -ltnp 'sport = :22', cloud firewall, router/NAT. |
For server-side errors, inspect recent systemd journal entries:
sudo journalctl -u ssh.service -u ssh.socket -b -n 60 --no-pager
On the client, a verbose SSH attempt can help identify the stage where the connection fails:
ssh -v username@SERVER_IP
Keep private keys, passwords, public IPs and usernames out of published troubleshooting screenshots where they are not needed.
Secure SSH after the first successful login
Installing OpenSSH is the start, not the entire security setup. Keep Ubuntu security updates current, use a dedicated non-root account where appropriate, and configure SSH key authentication. Verify a new key-based login before changing password authentication.
If you later choose to disable password login or change SSH ports, keep an existing session open, confirm the effective SSH configuration with sudo sshd -T, and test a new connection first. An overly aggressive security change can lock out legitimate administrators. Moving SSH off TCP 22 does not replace authentication or access control.
For a personal workstation, consider whether inbound SSH needs to be exposed beyond the local network. For a VPS, combine host firewall rules with provider network controls when appropriate.
Archived Ubuntu 24.04 hands-on lab: results and limits
We checked an existing OpenSSH Server installation in Ubuntu 24.04.5 LTS running under Windows Subsystem for Linux (WSL2). Unlike a minimal Docker container, this environment used systemd as PID 1, so it could report the actual ssh.socket and ssh.service units. The tests below reflect this environment; they are not a benchmark of a clean VM or Ubuntu 26.04.
| Recorded check | Observed result | What it proves |
|---|---|---|
| Environment and package | Ubuntu 24.04.5 LTS; OpenSSH package 1:9.6p1-3ubuntu13.20; systemd PID 1 | The SSH server package was installed, not that a fresh installation was performed during this session. |
| Systemd units | ssh.socket active (running); ssh.service active (running) | Socket activation can coexist with an already running SSH daemon. The service does not have to be inactive. |
| Listening ports | 0.0.0.0:22 and [::]:22 were listening; ss listed systemd and sshd | TCP port 22 was open for local listening on IPv4 and IPv6 interfaces; this alone does not prove remote login. |
| UFW application profile | UFW 0.36.2; OpenSSH profile 22/tcp; ufw allow OpenSSH added | The allow rule was configured, but ufw status verbose said inactive, so no active firewall filtering was verified. |
Measured listener output
On the tested WSL instance, the exact port check sudo ss -ltnp 'sport = :22' returned the following listening addresses (other columns omitted for readability):
LISTEN 0.0.0.0:22 users:(("sshd",pid=2014,...),("systemd",pid=1,...))
LISTEN [::]:22 users:(("sshd",pid=2014,...),("systemd",pid=1,...))
Interpretation: the SSH socket was accepting TCP connections on port 22 in the WSL network namespace. This is stronger than checking package status alone, but it is not the same as authenticating successfully with an SSH client.
End-to-end login: verification boundary
A Windows-to-WSL SSH test can be performed from PowerShell with ssh [email protected], followed by whoami, hostname and echo "$SSH_CONNECTION" inside the remote shell. However, the full output of this final login test was not provided alongside the three verified checks above. We therefore do not label a successful authentication as a measured result of this lab. The fourth image illustrates the client-side step and should be checked against the original terminal capture before publication.
Even when that localhost connection succeeds, it establishes access from the Windows host to WSL—not reachability from a second physical computer, an external network or the public Internet. For those scenarios, also verify Windows/WSL networking, routing, host firewalls and any provider rules.
The article separates documented Ubuntu behavior from the outcomes actually observed in our WSL2 test. We verified the installed OpenSSH package, real systemd units, IPv4/IPv6 listeners, the UFW application profile and the fact that UFW was inactive. Version-specific socket-activation guidance is supported by Ubuntu's official OpenSSH documentation and the 24.04 release notes. We do not imply that our WSL results demonstrate a public SSH service.
Frequently asked questions
How do I enable SSH on Ubuntu 24.04 or 26.04?
Install openssh-server, check ssh.socket and confirm a listener with ss. On new installs, socket activation normally starts handling connections automatically; verify rather than always forcing a separate service enable.
Is SSH installed by default on Ubuntu?
It depends on the image. Standard Ubuntu Desktop often lacks the incoming SSH server. Ubuntu Server can include it during installation, and Ubuntu cloud images often provide SSH access out of the box.
Why does systemctl show SSH as inactive when port 22 is listening?
With systemd socket activation, ssh.socket can listen before ssh.service is started by an incoming connection. Check both units and the listening socket.
Do I need to enable UFW to enable SSH?
No. If UFW is inactive, it does not block connections. If you decide to enable it, allow the actual SSH port and confirm a recovery path before doing so remotely.
Why can I SSH to the server from itself but not from another computer?
A local connection does not validate external routing, interface binding, provider firewalls or NAT. Check the listening address, then test from a separate reachable network client.
Technical references
Official documentation is used for version-specific facts; community posts are useful troubleshooting examples but not a substitute for the Ubuntu release notes.
- Ubuntu Server: OpenSSH server — package setup, configuration files and service management.
- Ubuntu 24.04 LTS release notes — systemd generator handling of
sshd_configfor socket activation. - Canonical: SSHd socket-based activation — change introduced in 22.10 and migration details.
- Ubuntu security: No open ports — installation differences and how to verify listening network ports.
Summary
On Ubuntu, sudo apt install openssh-server is the main setup step. Verify the TCP listener rather than relying on systemctl status ssh alone, especially on Ubuntu 24.04 and 26.04 where socket activation is the default. Check UFW and any cloud firewall before making the server remotely accessible, then confirm success with a real SSH login from another machine.
Once the SSH service is reachable, troubleshoot rejected keys with our public-key authentication guide or ShadeTerm SSH Terminal.