How to Install SSH on Ubuntu

Secure Shell (SSH) is a secure remote server or computer access protocol. It encrypts all client and server communication, providing high-security levels. This article will explain how to enable SSH on Ubuntu and provide step-by-step instructions on how to install SSH on Ubuntu.

SSH is pre-intstalled on most Linux distributions. If you’re using a customized distro such as a minimal docker image, and do not have SSH installed, we can easily install SSH on Ubuntu using APT package manager.

Install SSH on Ubuntu

Check if SSH is already enabled

Before enabling SSH on Ubuntu, it’s important to check if it is already enabled. You can do this by running the following command in the terminal –

sudo service ssh status
sandy@ZorinOS:~$ sudo service ssh status
Unit ssh.service could not be found.

If SSH is not enabled, you will get a message saying, “ssh: unrecognized service” or “Unit ssh.service could not be found”. If you get this message, proceed to the next step.

Install SSH if it is not enabled

To install SSH on Ubuntu, we can run the following commands –

Install SSH on Ubuntu
Install SSH on Ubuntu
  1. Update the package listsudo apt update
  2. Install the OpenSSH Server – sudo apt install openssh-server
  3. Verify the SSH installation by checking the SSH service status – sudo service ssh status
sandy@ZorinOS:~$ sudo service ssh status
 ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: e>
     Active: active (running) since Sat 2023-04-08 22:35:10 IST; 3min 10s ago
       Docs: man:sshd(8)
             man:sshd_config(5)
   Main PID: 8674 (sshd)
      Tasks: 1 (limit: 4562)
     Memory: 1.0M
     CGroup: /system.slice/ssh.service
             └─8674 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups

Apr 08 22:35:10 ZorinOS systemd[1]: Starting OpenBSD Secure Shell server...
Apr 08 22:35:10 ZorinOS sshd[8674]: Server listening on 0.0.0.0 port 22.
Apr 08 22:35:10 ZorinOS sshd[8674]: Server listening on :: port 22.
Apr 08 22:35:10 ZorinOS systemd[1]: Started OpenBSD Secure Shell server.
lines 1-15/15 (END)

If the SSH service is running, you will see a message saying, “ssh start/running“. SSH is now install and running on your Ubuntu system.

Configuring SSH on Ubuntu

SSH comes with a default configuration that works for most use cases. However, it’s important to understand the SSH configuration files and how to edit them to customize SSH settings to your needs.

Understanding SSH configuration files

There are two main SSH configuration files in Ubuntu –

  1. /etc/ssh/sshd_config: This file contains configuration settings for the SSH server.
  2. ~/.ssh/config: This file contains configuration settings for SSH clients.

Editing SSH configuration files

SSH config
SSH config

You will need a text editor such as Nano or Vim to edit the SSH configuration files. Here are some common configuration changes you may want to make –

  1. Changing SSH port: You can change the default SSH port (22) to any other port number you prefer. To do this, edit the Port line in /etc/ssh/sshd_config and change the port number to your desired port.
  2. Disabling root login: Disabling root login via SSH is generally recommended for security reasons. To disable root login, set the PermitRootLogin parameter to no in /etc/ssh/sshd_config.
  3. Allowing SSH access for specific users: You can allow or deny SSH access by adding their usernames to the AllowUsers or DenyUsers parameter in /etc/ssh/sshd_config.

After making changes to the SSH configuration files, you will need to restart the SSH service for the changes to take effect –

sudo service ssh restart

Connecting to SSH

Now you can use SSH command to login to any remote computer.

If you want to use SSH locally (on the same machine), open a terminal and run the following command –

ssh username@localhost

Replace the username with your actual Ubuntu username.

Connecting to Server Remotely

To connect to SSH remotely, you will need the IP address of the remote Ubuntu system. Once you have the IP address, open a terminal on your local machine and run the following command –

ssh username@ip_address

Replace the username with the username on the remote Ubuntu system and remote_ip_address with the IP address of the remote system.

After you enter the password for the remote user account, you will be connected to the remote Ubuntu system via SSH. Please make sure to enter the correct password.

By defaut SSH command tries to connect to the server on port 22. If the user has changed the default port, the server will return Timeout error. Use the -p argument with the custom port to direct SSH traffic to server’s correct SSH port.

ssh -p port username@ip_address

For more arguments, look at the SSH man page.

Conclusion

SSH is an important tool for remote access and Ubuntu management. Installing SSH on Ubuntu is easy. Once SSH is enabled, you can customize the configuration settings. For example, changing the default SSH port or disabling root login. By following the instructions in this article, you should now be able to enable and configure SSH on Ubuntu and connect to devices locally and remotely.

SHARE THIS POST

MassiveGRID Banner

Leave a Reply

Your email address will not be published. Required fields are marked *