How to Enable SSH (Secure Shell) in Ubuntu 21.04

This is a beginner’s guide shows how to install and setup SSH server and client in Ubuntu 21.04 Hirsute Hippo.

SSH, also known as Secure Shell or Secure Socket Shell, is one of the most have network services for securely remote login, file transfer. Ubuntu includes OpenSSH is its universe repositories. It’s the open-source version of the SSH tools used by administrators of Linux and other non-Windows.

Install OpenSSH in Ubuntu:

Install OpenSSH:

Ubuntu ships with the SSH client out-of-the-box. To install SSH server along with SFTP access from remote machines, open terminal and run command:

sudo apt install ssh

Start, restart, stop SSH service:

After installed the network services, it should run silently in the background. To check out the status, run command:

systemctl status sshd.service

You can replace status in the code with reload, restart, start, or stop to do relevant actions. For instance, the command below will reload the configuration:

systemctl reload sshd.service

Change SSH server configuration:

To configure the SSH server rules, e.g., listening port, allowed users, etc, open terminal and run command to edit the /etc/ssh/sshd_config file with nano text editor.

sudo nano /etc/ssh/sshd_config

When the file opens, you can do:

  • Change listening port by removing # at the beginning of line “#Port 22” and changing the number.
  • Add user authentication by AllowUsers username1 username2 usernameX. By default, all users is allowed to login. If specified, only users in the list can login.
  • Specifiy the local addresses ssh should listen on via ListenAddress.

And there are many more other configuration rules available. You can get the documentation by running command:

man sshd_config

After saving the changes via Ctrl+X keyboard shortcut follow with Y and Enter, remember to reload the SSH service by running the previous systemctl command.

Merilyn Ne
Hi, I'm Merilyn Ne, a geek who has been working on Ubuntu Linux for many years and would like to write useful tips for beginners. Forgive me for language mistakes. I'm not a native speaker of English.