How To Enable SSH on Ubuntu (All Versions)?

SSH (Secure Shell) is a protocol created to connect and manage systems remotely in a secure manner. SSH is the most popular protocol to manage Linux and Network systems via a command-line interface. As a Linux distribution, Ubuntu supports the SSH protocol as an SSH server and SSH client. In this tutorial we will learn installing the SSH service, starting the SSH service, and enabling the firewall to permit SSH connections. By the way, SSH is a protocol and OpenSSH is a tool or implementation of the SSH where most Linux distributions including Ubuntu uses the OpenSSH as an SSH server and SSH client.

Install SSH Service (OpenSSH Server)

The SSH service is provided via the openssh-server package in deb based distributions like Ubuntu, Debian, Mint, Kali, etc. First, we will install the openssh-server package with the apt or apt-get command. As an installation, updating, and removing packages are administrative tasks we need root privileges we will also use the sudo command.

Install OpenSSH Server For Ubuntu, Debian, Mint, Kali with apt Command:

sudo apt install openssh-server

Install OpenSSH Server For Ubuntu, Debian, Mint, Kali with apt-get Command:

sudo apt-get install openssh-server

Check SSH Service Status

The SSH service or OpenSSH server service is named as sshd. The systemctl command is used to manage service where the SSH service status can be displayed with the following command.

systemctl status sshd
Check SSH Service Status
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-12-08 13:41:31 +03; 2h 1min ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 71142 (sshd)
Tasks: 1 (limit: 4615)
Memory: 5.8M
CGroup: /system.slice/ssh.service
└─71142 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
Ara 08 13:41:31 ubuntu systemd[1]: Starting OpenBSD Secure Shell server…
Ara 08 13:41:31 ubuntu sshd[71142]: Server listening on 0.0.0.0 port 22.
Ara 08 13:41:31 ubuntu sshd[71142]: Server listening on :: port 22.
Ara 08 13:41:31 ubuntu systemd[1]: Started OpenBSD Secure Shell server.
Ara 08 13:52:44 ubuntu sshd[72288]: Accepted password for ismail from 192.168.146.129 port 64548 ssh2
Ara 08 13:52:44 ubuntu sshd[72288]: pam_unix(sshd:session): session opened for user ismail by (uid=0)
Ara 08 14:04:15 ubuntu sshd[72387]: Accepted password for ismail from 192.168.146.129 port 64629 ssh2
Ara 08 14:04:15 ubuntu sshd[72387]: pam_unix(sshd:session): session opened for user ismail by (uid=0)

Start SSH Service

The SSH service can be started with the systemctl command. But service management requires administrative privileges which can be provided with the sudo command. Below we start the SSH service.

sudo systemctl start sshd

Enable SSH Service For Auto-start At Boot

The SSH service can be started manually which is described previously. But starting the SSH service every time manually on system boot is not feasible and possible. The SSH service can be set to automatically start at boot by using the systemctl command like below. We will also provide the enable command and the ssh as the service name.

sudo systemctl enable ssh

Allow Firewall For SSH Port

Ubuntu installs and enables the local firewall by default which is called iptables. The iptables firewall can be managed with different tools where the ufw (Ubuntu Firewall) is the easiest way. By default, the SSH port number 22 is blocked by the firewall. We should add a rule which allows connections to the local SSH port TCP 22 from other systems. Again we will provide the sudo command to the “ufw allow ssh” command.

sudo ufw allow ssh

Alternatively we can provides the SSH service port number

sudo ufw allow ssh

Leave a Comment