Installing and Enabling OpenSSH on Ubuntu 22.04 or 20.04
Want a quick, reliable way to jump into your machine from anywhere?
This guide walks you through the exact steps to get OpenSSH up and running on Ubuntu 22.04 LTS or 20.04 LTS, plus a few sanity checks that will save you hours of frustration later.
1. Grab the package
sudo apt update sudo apt install openssh-server
apt update pulls fresh metadata; without it, apt install might grab an old copy or fail entirely.
The package name is openssh-server—the client (ssh) comes pre‑installed on most Ubuntu installs.
2. Make the daemon stick around
sudo systemctl enable --now ssh
enable tells systemd to start SSH automatically at boot, while --now launches it immediately so you can test right away.
If you skip this step, every reboot will kill your ability to remote in until you remember to hand‑run the service.
3. Harden the defaults (optional but recommended)
Open /etc/ssh/sshd_config in your favorite editor:
sudo nano /etc/ssh/sshd_config
- Find #PermitRootLogin prohibit-password and change it to
PermitRootLogin no – you’ll never need a root password over SSH.
- Ensure PubkeyAuthentication yes is enabled so key‑based logins work.
I ran into an odd issue after a kernel upgrade where this line was commented out by default; once I uncommented it, my keys started working again.
After editing, reload the service:
sudo systemctl reload ssh
Reloading applies changes without dropping any active connections.
4. Open the firewall to SSH traffic
If you’re running UFW (Uncomplicated Firewall), allow the standard port with:
sudo ufw allow OpenSSH
UFW blocks everything by default, so this one rule is all you need for a secure, accessible server.
5. Confirm it’s alive and reachable
systemctl status ssh
You should see “Active: active (running)” in green.
Try connecting from the same machine to double‑check:
ssh localhost
If that works, you’re good to go from any other host on your network.
6. Common hiccups and quick fixes
- No connection? Check /var/log/auth.log for “Connection closed by …” messages; they often point to a firewall or mis‑configured sshd_config.
- Key authentication fails? Make sure your public key is in $HOME/.ssh/authorized_keys on the remote host and has 600 permissions.
I once saw this issue after a fresh install where the folder was left at 755, and SSH refused every key.
- Password prompts still appear? If you accidentally set PasswordAuthentication yes, remove or comment that line to enforce keys only.
That’s it—OpenSSH is now installed, enabled, and ready for secure remote work.