SSH, short for Secure Shell, lets you reach a remote machine over an encrypted connection. Once you enable SSH in Ubuntu, you can run admin commands, move files, and handle routine tasks without sitting at the physical keyboard.

This walkthrough covers Ubuntu 20.04, 22.04, and 24.04, from installing the server to logging in remotely.

Quick Commands to Enable SSH in Ubuntu

Here are the operations you will reach for most often before working through the full setup.

What you want to doCommand
Install the SSH server packagesudo apt install openssh-server
Check whether SSH is activesudo systemctl status ssh
Start the SSH servicesudo systemctl start ssh
Stop the SSH servicesudo systemctl stop ssh
Run SSH at every bootsudo systemctl enable ssh
Turn SSH off for goodsudo systemctl disable --now ssh
Open the SSH port in the firewallsudo ufw allow ssh
Log into a remote hostssh username@ip_address

How to Enable SSH in Ubuntu for the First Time

A fresh Ubuntu install blocks incoming SSH traffic. You need root or a sudo-capable account to change that.

1. Install the OpenSSH package. Open a terminal with Ctrl+Alt+T, refresh the package index, and pull in the server:

sudo apt update
sudo apt install openssh-server

Type your password when prompted and press Enter to let the install finish.

2. Confirm the service is running. The daemon starts on its own after installation. Check it with the systemctl utility:

sudo systemctl status ssh

A working result looks like this:

● ssh.service - OpenBSD Secure Shell server
    Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
    Active: active (running) since Thu 2026-06-04 09:00:00 IST; 2min ago

Press q to drop back to the shell prompt.

3. Allow SSH through the firewall. Ubuntu ships with UFW. If it is switched on, one command opens the port:

sudo ufw allow ssh

That is all it takes to enable SSH in Ubuntu and make the server reachable.

Connecting to Your SSH Server Over LAN

Linux and macOS already include an SSH client. Windows 10 and 11 ship one inside PowerShell or Command Prompt. The ssh login command follows this pattern:

ssh username@ip_address

Swap in your real account name and the machine’s address. To find the address, run:

ip a

Look for the inet line under your active adapter, for example 10.0.2.15. Then connect:

ssh [email protected]

On the first connection you will see a fingerprint warning:

The authenticity of host '10.0.2.15 (10.0.2.15)' can't be established.
ECDSA key fingerprint is SHA256:Vybt22mVXuNuB5unE++yowF7lgA/9/2bLSiO3qmYWBY.
Are you sure you want to continue connecting (yes/no)?

Type yes. Ubuntu saves the host key, asks for your password, and drops you into the remote shell with a welcome banner. Every flag the client accepts is listed in the full ssh command reference.

Reaching SSH Behind a NAT Router

Getting to a home machine from outside your network takes two extra steps.

First, find your public IP by visiting api.ipify.org in a browser. Next, open your router’s admin panel and forward external port 22 to the private IP of the Ubuntu host. Then connect using the public address:

ssh username@public_ip_address

Exposing port 22 directly draws automated login attempts. A practical fix is to forward a non-standard external port to port 22 internally. To skip passwords altogether, set up key-based login; ssh-keygen creates the key pair you place on the server.

Turning SSH Off When It Is Not Needed

If you no longer want the service running, stop it and keep it from restarting at the next boot:

sudo systemctl disable --now ssh

To bring it back:

sudo systemctl enable --now ssh

Troubleshooting Common SSH Problems

The daemon refuses to start? Read the journal with sudo journalctl -u ssh. A broken /etc/ssh/sshd_config is the usual cause. The sshd daemon has a built-in config test, so run sudo sshd -t, fix what it reports, then start the service.

Seeing “Connection refused” on port 22? Check that the service is up with sudo systemctl status ssh and that UFW holds the rule with sudo ufw status. Re-add it using sudo ufw allow ssh if it is gone.

“Host key verification failed” shows up after a machine is reinstalled and its key changes. Clear the stale record with ssh-keygen -R ip_address, reconnect, and accept the new fingerprint.

“Permission denied (publickey)” means your private key is missing or unmatched. Confirm ~/.ssh/id_rsa or ~/.ssh/id_ed25519 exists, that the public half sits in ~/.ssh/authorized_keys on the server, and that the file uses permissions 600. With SSH working, you can move files over the same encrypted channel using the scp command, or copy from Linux to a Windows box.

FAQs

Does this work on Ubuntu 22.04 and 24.04?

Yes. The openssh-server package and systemctl commands are the same across Ubuntu 20.04, 22.04, and 24.04.

Which port does SSH use by default?

Port 22. You can switch to another port in sshd_config to cut down on automated probes.

How do I avoid typing a password each time?

Generate a key pair and place the public half in the server’s authorized_keys file. SSH then authenticates with the key automatically.

Can I load my key once instead of per connection?

Yes. Add it to the agent with the ssh-add command, and the passphrase is cached for the session.

How do I manage several servers without memorising addresses?

Store each server’s details in ~/.ssh/config under a short alias, then connect with one word instead of the full address.

Keeping Your SSH Setup Secure

Those steps are all you need to enable SSH in Ubuntu on any supported release. With the service running and the firewall rule in place, you can run commands and move files from anywhere.

For tighter security, switch to a non-default port, enforce key-based authentication, and keep openssh-server updated. Small habits like these keep automated attacks at arm’s length.

Willie has over 15 years of experience in Linux system administration and DevOps. After managing infrastructure for startups and enterprises alike, he founded Command Linux to share the practical knowledge he wished he had when starting out. He oversees content strategy and contributes guides on server management, automation, and security.