How to Install and Configure OpenSSH Server on Ubuntu
-
Jason Yang - 05 Dec, 2025
- Updated 04 Jan, 2026
- Views —
SSH (Secure Shell) is the standard network protocol used to communicate securely between computers and transfer data. Its primary feature is that the communication channel is encrypted, making it safe to use even on insecure networks.
The most widely used SSH implementation is the OpenSSH suite, which includes tools for remote operations (ssh, scp, sftp) and key management. In this guide, we will walk through setting up an SSH server on Ubuntu so you can access your machine remotely.
1. Install OpenSSH Server
While the OpenSSH client is usually pre-installed on Ubuntu, you need to install the server component to accept incoming connections.
Update your package list and install the server:
sudo apt update
sudo apt install openssh-server
Verify the installation:
ssh -V
# Output example: OpenSSH_8.9p1... (Version may vary)
2. Configure the Firewall (UFW)
Ubuntu uses UFW (Uncomplicated Firewall) by default. You must explicitly allow SSH traffic (Port 22).
sudo ufw allow ssh
Enable the firewall:
sudo ufw enable
⚠️ Warning: If you are configuring a remote server via a temporary session, enabling UFW without allowing SSH first may disconnect you. Ensure you see “Rule added” before enabling.
Verify the status:
sudo ufw status
Output should show 22/tcp set to ALLOW.
3. Start and Enable SSH Service
Start the SSH service and enable it to launch automatically on system boot.
sudo systemctl start ssh
sudo systemctl enable ssh
Check the service status to ensure it is running without errors:
sudo systemctl status ssh
Look for Active: active (running) in the output.
4. Test the Connection
Option A: Local Loopback Test
You can try connecting to your own machine to verify the service is active.
ssh username@127.0.0.1
Type yes to accept the fingerprint and enter your password.
Option B: Connect from Another Machine (Real World)
To connect from a different computer, you need your server’s IP address.
**Connect from a remote client:**Bash
ssh username@192.168.1.50
**Find your IP address:**Bash
hostname -I
# Example Output: 192.168.1.50
Summary & Next Steps
You now have a fully functional SSH server running on Ubuntu.
- Configuration: The main configuration file is located at
/etc/ssh/sshd_config. You can edit this file to change the default port (22) or modify security settings. - Security Tip: For production environments, it is highly recommended to disable password authentication and set up SSH Key-based authentication for better security.