How to Enable SSH on Ubuntu

Secure Shell (SSH) is a network protocol that allows you to securely connect to a remote server or computer over an encrypted connection. With SSH enabled, you can remotely manage your Ubuntu system, run administrative commands, and transfer files securely using tools like scp
and sftp
.
This guide explains how to enable SSH on Ubuntu 20.04, 22.04, 24.04, and 26.04, connect to it remotely, and manage the SSH service.
Quick Reference
| Task | Command |
|---|---|
| Install OpenSSH server | sudo apt install openssh-server |
| Check SSH service status | sudo systemctl status ssh.service ssh.socket |
| Start SSH on Ubuntu 20.04/22.04 | sudo systemctl start ssh.service |
| Start SSH on Ubuntu 24.04/26.04 | sudo systemctl start ssh.socket |
| Stop SSH | sudo systemctl stop ssh.service ssh.socket |
| Enable SSH on boot (Ubuntu 20.04/22.04) | sudo systemctl enable ssh.service |
| Enable SSH on boot (Ubuntu 24.04/26.04) | sudo systemctl enable ssh.socket |
| Disable SSH | sudo systemctl disable --now ssh.service ssh.socket |
| Allow SSH through UFW | sudo ufw allow ssh |
| Connect to remote host | ssh username@ip_address |
For a printable quick reference, see the SSH cheatsheet .
Enabling SSH on Ubuntu
By default, on fresh installs, Ubuntu does not allow SSH connections. You must enable it manually.
Follow the steps below as root or a user with sudo privileges to install and enable SSH on your Ubuntu system:
Open the terminal using
Ctrl+Alt+Tand install theopenssh-serverpackage:Terminalsudo apt update sudo apt install openssh-serverWhen prompted, enter your password, then press
Enterto continue the installation.
After installation, Ubuntu enables OpenSSH automatically. Ubuntu 20.04 and 22.04 run
ssh.serviceat boot. Verify that the service is running:Terminalsudo systemctl status ssh.serviceThe output should show the service as
active (running)and enabled to start on system boot:output● ssh.service - OpenBSD Secure Shell server Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2026-09-01 12:34:00 CEST; 9h ago ...Press
qto exit the status screen and get back to the command line prompt.Ubuntu 24.04 and 26.04 use
ssh.socketby default, a behavior introduced in Ubuntu 22.10. The socket listens for incoming connections and startsssh.servicewhen a client connects. Check the socket unit instead:Terminalsudo systemctl status ssh.socketLook for
Active: active (listening)in the output. Before the first connection,ssh.servicemay be inactive, which is expected and does not mean that SSH is broken.Ubuntu ships with a firewall configuration tool called UFW. If the firewall is enabled on your system, make sure to open the SSH port:
Terminalsudo ufw allow ssh
That is it. You can now connect to your Ubuntu system via SSH from any remote machine. Linux and macOS systems include an SSH client by default. On Windows 10 and 11, you can use the built-in ssh client from PowerShell or Command Prompt, or use PuTTY
if you prefer a graphical SSH client.
Connecting to the SSH Server
To connect to your Ubuntu machine over LAN, invoke the ssh command
followed by the username and the IP address in the following format:
ssh username@ip_addressIf you do not know the IP address, you can easily find it using the ip command
:
ip a
As you can see from the output, the system IP address is 10.0.2.15.
Once you have found the IP address, log in to the remote machine by running the following SSH
command:
ssh linuxize@10.0.2.15When you connect the first time, you will see a security warning like this:
The authenticity of host '10.0.2.15 (10.0.2.15)' can't be established.
ED25519 key fingerprint is SHA256:Vybt22mVXuNuB5unE++yowF7lgA/9/2bLSiO3qmYWBY.
Are you sure you want to continue connecting (yes/no/[fingerprint])?Type yes, and you will be prompted to enter your password.
Warning: Permanently added '10.0.2.15' (ED25519) to the list of known hosts.
linuxize@10.0.2.15's password:Once you enter the password, you will be logged into your system and greeted with the default Ubuntu message:
Welcome to Ubuntu 24.04 LTS (GNU/Linux 6.8.0-45-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
...You are now logged in to your Ubuntu machine.
Connecting to SSH behind NAT
To connect to your home Ubuntu machine over the Internet, you will need to know your public IP address and configure your router to accept incoming traffic on port 22 and forward it to the Ubuntu system where SSH is running.
Find Your Public IP Address To determine the public IP address of the machine you are trying to SSH to, visit the following URL:
https://api.ipify.org.Configure Port Forwarding When it comes to setting up port forwarding on your router, each device has its own interface and terminology. You should consult your router’s documentation for instructions on setting up port forwarding. In short, you need to enter the port number where requests will be made (the default SSH port is 22) and the private IP address you found earlier (using the
ip acommand) of the machine where SSH is running.Connect Using Public IP Once you have found the IP address, and configured your router, you can log in by typing:
Terminalssh username@public_ip_address
If you are exposing your home machine to the Internet, it is a good idea to implement some security measures. The most basic one is to configure your router to accept SSH traffic on a non-standard port and to forward it to port 22 on the machine running the SSH service.
You can also set up an SSH key-based authentication and connect to your Ubuntu machine without entering a password.
Disabling SSH on Ubuntu
To turn off the SSH server on any of the supported Ubuntu releases, disable and stop both systemd units at once:
sudo systemctl disable --now ssh.service ssh.socketOnly one of these units is normally enabled. Specifying both prevents ssh.socket from continuing to listen on port 22 and starting the service when a client connects.
Later, to re-enable SSH on Ubuntu 24.04 or 26.04, enable and start the socket:
sudo systemctl enable --now ssh.socketOn Ubuntu 20.04 or 22.04, enable and start the service instead:
sudo systemctl enable --now ssh.serviceTroubleshooting
SSH service fails to start
Run sudo journalctl -u ssh.service -u ssh.socket to see the error. A common cause is a misconfigured /etc/ssh/sshd_config. Test the config with sudo sshd -t before restarting the service or socket.
Connection refused on port 22
Confirm that SSH is running with sudo systemctl status ssh.service ssh.socket. If UFW is active, verify the rule is in place with sudo ufw status and re-run sudo ufw allow ssh if it is missing. Our guide on the SSH connection refused error
covers the rest of the checks, from the listening address to the network path.
Host key verification failed
This happens when the remote host’s key has changed (for example, after a reinstall). Remove the old entry with ssh-keygen -R ip_address and reconnect.
Permission denied (publickey)
If you use key-based auth, ensure the correct private key is available (~/.ssh/id_rsa or ~/.ssh/id_ed25519) and that ~/.ssh/authorized_keys on the server contains the matching public key with permissions 600.
FAQ
Does this work on Ubuntu 20.04, 22.04, 24.04, and 26.04?
Yes. All four releases use the openssh-server package. Ubuntu 20.04 and 22.04 run ssh.service at boot, while Ubuntu 24.04 and 26.04 listen through ssh.socket and start the service when a client connects.
What port does SSH use by default?
SSH uses port 22 by default. You can change the default SSH port
to reduce automated login attempts.
How do I connect without a password?
Set up SSH key-based authentication
to log in using a key pair instead of a password.
How do I connect to multiple servers more easily?
Define your hosts in the SSH config file
so you can connect with a short alias instead of typing the full address each time.
Conclusion
We have shown you how to install and enable SSH on Ubuntu systems. With SSH enabled, you can manage your system remotely, securely transfer files, and perform everyday administrative tasks without physical access.
If you manage multiple systems, you can simplify your workflow by defining all your connections in the SSH config file . Changing the default SSH port adds an extra layer of security to your system by reducing the risk of automated attacks.
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page