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-serverStep 2: Start and Enable SSH service
sudo systemctl enable ssh
sudo systemctl start ssh
sudo systemctl status ssh # check if SSH is runningStep 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 sshusersStep 4: Restart SSH service
sudo systemctl restart sshStep 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 statuskc@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 rebootLast updated on
