Skip to Content

Setup SSH on Ubuntu

Learn how to set up SSH on Ubuntu for secure remote access and management.

karchunt

Kar Chun Tan

Creator

Metadata

Wed Dec 24 2025

2 min read

213 words

Setup SSH on Ubuntu

SSH (Secure Shell) is a protocol that allows secure remote access to a computer over an unsecured network. Today, I will guide you through the best practices for setting up SSH on an Ubuntu system.

Step 1: Install OpenSSH Server

sudo apt-get update sudo apt-get install -y openssh-server

Step 2: Start and Enable SSH service

sudo systemctl enable ssh sudo systemctl start ssh sudo systemctl status ssh # check if SSH is running

Step 3: Configure SSH settings

To enhance security, you can modify the SSH configuration file by searching the following settings:

  • PasswordAuthentication no: Disable password authentication to use key-based authentication.
  • PermitRootLogin no: Disable root login via SSH.
  • AllowUsers your_username: Restrict SSH access to specific users.
  • AllowGroups your_group: Restrict SSH access to specific groups.
sudo nano /etc/ssh/sshd_config
/etc/ssh/sshd_config
PasswordAuthentication no PermitRootLogin no AllowUsers user1 user2 user3 AllowGroups sshusers

Step 4: Restart SSH service

sudo systemctl restart ssh

Step 5: Configure Firewall

Configuring firewall is very important to secure your server. By default, Ubuntu uses UFW (Uncomplicated Firewall) and when you enable it, SSH connections are blocked. To allow SSH connections, run the following command:

sudo ufw allow ssh sudo ufw enable sudo ufw status
kc@kcserver:~$ sudo ufw status Status: active To Action From -- ------ ---- 22/tcp ALLOW Anywhere 22/tcp (v6) ALLOW Anywhere (v6)

Step 6: Reboot the server

The final step is to reboot the server to ensure all changes take effect.

sudo reboot
Last updated on