Enable SSH on Ubuntu, Pop!_OS & Other Linux Distros

Sharing is caring!

Tips on how to enable SSH on Ubuntu, Pop!_OS, and other Linux distributions. Secure Shell (SSH) is a secure communication protocol between a client and a server. Installing the OpenSSH server is one of the primary things we do after setting up a Linux machine. We use Secure Shell to make our administrative tasks easier and manage Linux machines remotely.

If you are interested in tinkering with Linux distributions in your own home lab, be sure to check out our home server build tutorial.

Enable SSH on Ubuntu, Pop!_OS, and Other Linux Distros

Before we enable SSH on Ubuntu or any other Linux distro, we want to first make sure that we have “root” privileges to do so. The default “root” account normally has Super Administrator privileges to install the SSH server.

Open CTRL + ALT +T to open a Terminal Window and type in the following commands one by one to install the Open SSH server package.

sudo apt update 
sudo apt install openssh-server

The above commands will initiate the install process. When a password request is made please type in your “root” user password to continue. If prompted with a Y/N to continue type in Y and press Enter.

Next, we will allow SSH firewall rules by issuing the following command. In some instances, SSH firewall rules do not need to be manually specified.

sudo ufw allow ssh 

Starting the (SSH) Service automatically on Linux

Once installed, the SSH service will start automatically on Linux during boot. If you want to make sure that the SSH service started up properly, initiate the following commands.

 

sudo systemctl status ssh

 

You should now be able to see the OpenSSH Server status as shown below.

The SSH server status should say active: running

Enable SSH on Ubuntu

Creating Multiple Root Users in Linux for SSH Access

We can use the “root” account which already has sudo privileges or we can set up new “root” privileged accounts for multiple admin users.

Below are the steps to create a new user account in Linux and assign them sudo privileges. The newly created users will be able to access SSH while enjoying full root privileges.

Open up a command terminal by pressing CTL+ALT+T as the current root user. Using the command below to create a new user.  You can replace the “username” field with any name you would like to use.

 adduser username

Once an account is created, set a strong password when prompted.

See an example of a sample account we created below called “tesla”

add ssh user ubuntu

Assigning Sudo Privileges To Linux Users

You can use the following command to assign root privileges to new or existing Linux users. Replace the username field with the user’s name to who you would like to assign sudo privileges.

 usermod -aG sudo username

you won’t get a confirmation after this command but you should not see any errors either.

Confirm Sudo Privileges for Linux Users

Once you assign “Sudo” privileges to a Linux user, you can test it out to make sure it is working by using the commands below.

In order to log in using the new account you’ve created, execute the following command.

 su – username

In the example below, we will log in as the user “tesla” which we created earlier.

SSH on Ubuntu

To verify that you are successfully logged in as the intended user, execute the following command.

 whoami 

Here is another popular command to assume the Identity of the root user in  Linux.

The following command allows you to assume the identity of a root user in a session without disturbing the current user’s environment.

 sudo su

Enter the password when prompted and you are in!

You should now be able to run commands such as sudo apt-get update using the newly created account.

You can try these out for yourself

 sudo apt-get update
 sudo apt-get upgrade

Removing Linux Users

This article wouldn’t be complete without teaching you how to remove user accounts in Linux.

First, we will get a list of all users in the Linux system by issuing the following command.

 getent passwd

If we wish to look up the existence of a specific user in the system, we can issue the following command.

 getent passwd | grep “nameofuser” without quotes

We can then easily remove the Linux user by typing in the following command.

 sudo userdel “nameofuser” without quotes

You can further clean up a deleted user’s home directory and mail spool by issuing the following command.

 sudo userdel -r “nameofuser” without quotes

For most, the following command won’t apply but if you have SELinux users mapped, you can remove the mapping using the following command.

 sudo userdel -Z -r -f “nameofuser” without quotes

We hope this article was helpful and made it easier for you to run administrative tasks remotely via Secure Shell. If you’ve enjoyed this content, please consider subscribing to our Facebook Group @ Tech Really.

    1. JB Sydney AU June 3, 2022

    Add Your Comment

shares