How to Enable SSH on Ubuntu
Learn how to enable ssh on ubuntu with OpenSSH server installation, systemd service management, UFW firewall rules, and key-based security hardening.

5 min read
Learn how to enable ssh on ubuntu with OpenSSH server installation, systemd service management, UFW firewall rules, and key-based security hardening.
- Prerequisites and Supported Releases
- Step 1: Installing the OpenSSH Server Package
- Step 2: Starting and Enabling the SSH Service
Secure Shell (SSH) is the standard cryptographic network protocol used by developers and system administrators to manage remote Linux systems securely.
While cloud server images typically ship with the OpenSSH daemon pre-installed, desktop installations and minimal server builds frequently have SSH disabled by default.
Enabling SSH on an Ubuntu machine allows you to log into a remote command shell, transfer files securely using SFTP or SCP, and forward network ports through encrypted tunnels.
In modern Ubuntu releases like Ubuntu 24.04 LTS, OpenSSH utilizes systemd socket activation by default to optimize boot performance and resource consumption.
In this guide, we walk through how to enable ssh on ubuntu from scratch, configure the firewall, verify listening sockets, and secure remote access.
Complete step-by-step guide to installing, configuring, and enabling the OpenSSH server daemon on Ubuntu 24.04 LTS and 22.04 LTS. Covers systemd service and socket activation, UFW firewall rule configuration, verifying listening ports, and connecting remotely from Windows, macOS, or Linux.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- A computer or virtual machine running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
- A user account with
sudoadministrative privileges. - Access to a local terminal or graphical desktop terminal window.
- An active local network or Internet connection.
Step 1: Installing the OpenSSH Server Package
Ubuntu repositories include OpenSSH through the openssh-server package.
First, update your local APT repository cache, then install the OpenSSH server daemon package:
# Update package lists:
sudo apt update
# Install the OpenSSH server package:
sudo apt install -y openssh-server
# Terminal installation output:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
openssh-server openssh-sftp-server
Setting up openssh-server (1:9.6p1-3ubuntu13.4) ...
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 ECDSA key; this may take some time ...
Creating SSH2 ED25519 key; this may take some time ...
Step 2: Starting and Enabling the SSH Service
Once the installation completes, the SSH service starts automatically and configures itself to launch on system boot.
In Ubuntu 24.04 LTS, OpenSSH can be managed via the classic ssh.service or the modern ssh.socket activation unit.
Verify the running status of the SSH service using systemctl:
# Check active SSH status:
sudo systemctl status ssh
# Output:
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/usr/lib/systemd/system/ssh.service; enabled; preset: enabled)
Active: active (running) since Wed 2026-10-21 14:22:10 UTC; 2min ago
Main PID: 3124 (sshd)
Tasks: 1 (limit: 4613)
Memory: 3.1M
CPU: 12ms
CGroup: /system.slice/ssh.service
└─3124 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
Enabling SSH on Boot
If the service is inactive, start and enable it so that it launches automatically whenever your machine restarts:
# Start the SSH service immediately:
sudo systemctl start ssh
# Enable SSH on system boot:
sudo systemctl enable ssh
Step 3: Opening SSH Through the UFW Firewall
If the Uncomplicated Firewall (UFW) is active on your Ubuntu system, incoming connections on port 22 will be blocked by default.
You must explicitly add a firewall rule to allow SSH traffic before attempting a remote connection.
Use the registered UFW application profile or specify port 22 directly:
# Allow SSH using the OpenSSH application profile:
sudo ufw allow OpenSSH
# Alternatively, allow port 22 directly:
sudo ufw allow 22/tcp
# Reload firewall rules to apply changes:
sudo ufw reload
# Verify active firewall rules:
sudo ufw status
Step 4: Finding Your Server's IP Address and Connecting
To connect from a remote client, you need your Ubuntu machine's IP address.
Query your local or public IP address using the ip command:
# Find active IPv4 address:
ip -br addr show
# Sample output:
lo UNKNOWN 127.0.0.1/8 ::1/128
eth0 UP 192.168.1.150/24 fe80::5054:ff:fe12:3456/64
Connecting from a Remote Machine
From your remote workstation (macOS, Linux terminal, or Windows PowerShell), connect using your Ubuntu username and the target IP address:
ssh [email protected]
# The first time you connect, confirm the host fingerprint:
The authenticity of host '192.168.1.150 (192.168.1.150)' can't be established.
ED25519 key fingerprint is SHA256:4d8a1c9b2e3f4a5c6d7e8f9a0b1c2d3e4f5a6b7c8d9.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.1.150' (ED25519) to the list of known hosts.
[email protected]'s password:
Configuring Remote SSH Client Shortcuts (~/.ssh/config)
Typing full IP addresses and usernames repeatedly becomes tedious when managing multiple Ubuntu systems.
OpenSSH clients support configuring persistent host definitions inside your local workstation's ~/.ssh/config file.
By defining shortcuts, you can connect using a simple memorable alias like ssh production-web:
# ~/.ssh/config on your local machine
Host ubuntu-server
HostName 192.168.1.150
User sysadmin
Port 22
IdentityFile ~/.ssh/id_ed25519
ServerAliveInterval 60
ServerAliveCountMax 3
Managing SSH Keys with ssh-agent
When protecting private keys with strong passphrases, retyping the passphrase on every single connection creates friction.
The OpenSSH authentication agent (ssh-agent) stores decrypted private keys in memory for the duration of your local desktop session.
Start the agent in your local terminal and cache your key identity using ssh-add:
# Initialize ssh-agent in current shell session:
eval "$(ssh-agent -s)"
# Add your private key to the agent:
ssh-add ~/.ssh/id_ed25519
# List cached key identities:
ssh-add -l
Hardening OpenSSH: Custom Ports and Disabling Password Authentication
Once your SSH key authentication is verified, harden the daemon configuration against public Internet scans.
Create a dedicated configuration drop-in file in /etc/ssh/sshd_config.d/ to disable password logins and enforce cryptographic keys:
If changing the default listening port, remember to update your UFW firewall rules before restarting the SSH service.
# Create security configuration snippet:
cat << 'EOF' | sudo tee /etc/ssh/sshd_config.d/99-hardening.conf
PasswordAuthentication no
PermitRootLogin no
PubkeyAuthentication yes
EOF
# Validate syntax and restart the daemon:
sudo sshd -t && sudo systemctl restart ssh
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
ssh: connect to host X.X.X.X port 22: Connection refused
Cause: The openssh-server package is not installed, or the SSH service/socket is not running.
Resolution: Install the package and start the service with sudo systemctl start ssh.
sudo systemctl restart ssh && sudo systemctl status ssh
ssh: connect to host X.X.X.X port 22: Connection timed out
Cause: A firewall (UFW, cloud security group, or router NAT) is dropping incoming packets on port 22.
Resolution: Check UFW rules on the server and ensure port 22 is allowed.
sudo ufw allow OpenSSH && sudo ufw reload
Security Best Practices and Hardening
Always configure public key authentication and disable password logins in /etc/ssh/sshd_config.d/ on Internet-facing servers.
Consider changing the default SSH port from 22 to a non-standard high port (e.g. 2222) to drastically reduce automated bot scan noise.
Implement Fail2ban or SSH rate limiting with UFW (sudo ufw limit OpenSSH) to protect against brute-force attacks.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Create a Sudo User on Ubuntu — Create non-root administrative accounts for secure SSH logins.
- Initial Server Setup on Ubuntu 24.04 LTS — Complete security hardening and SSH key configuration guide.
- How to Configure Networking with Netplan on Ubuntu — Set up static IP addresses so your SSH endpoint never changes.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
openssh-server manually.sudo systemctl stop ssh and prevent it from starting on boot with sudo systemctl disable ssh.ssh username@your_ubuntu_ip.ssh.socket) listens on port 22 and spawns ssh.service on demand when a connection arrives, reducing idle memory usage on small instances.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides

Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!