How to Install and Use SSH on Ubuntu 20.04 | 18.04

This brief tutorial shows students and new users how to use the ssh command in Ubuntu to connect to establish secure communication to a remote system over SSH protocol.

Secure Shell (SSH) is a cryptographic network protocol that provides encrypted compunction between and clients and servers. It replaces previously unsecured network clients in a networked environment.

If you’re a student or new user looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS…. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use.

Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other devices…

When using Ubuntu, you will find that Linux isn’t so different than Windows and other operating systems in so many ways, especially when it comes to using the system to get work done.

Both Ubuntu and Windows systems allow you to be productive, easy to use, reliable and enable you to install and run thousands of programs from gaming to productivity suite software for individuals and businesses.

This tutorial is going to show you how.

When you’re ready to learn how to use the ssh commands, follow the guide below:

About ssh command:

Secure Shell (SSH) is a cryptographic network protocol that provides encrypted compunction between and clients and servers. It replaces previously unsecured network clients in a networked environment.

There are multiple SSH clients both commercial and opensource. OpenSSH client is the most popular SSH client and comes preinstalled on most Linux distributions by default.

Syntax:

Syntax is the rule and format of how the ssh command can be used… These syntax options can be reordered, but a straight format must be followed.

If you haven’t installed SSH server, the commands below will install it on the server. Run the commands below to install openssh-server.

sudo apt update
sudo apt install openssh-server

Below is an example syntax of how to use the ssh command.

ssh [OPTIONS] [USER@]:HOST

Options:

The command line options are switches or flags that determined how the commands are executed or controlled… they modify the behavior of the commands… they are separated by spaces and followed after the commands…

Below are some options of the ssh command:

    Options:Replace Options: with the options to run with the ssh command
    -lUse the -l option to specify a username for connecting
    -p  Use the -p option to specify a unique port number to connect to
    -h, –helpDisplay a help message and exit.
    -vUse the -v option to print out debugging messages

To connect to a remote server using SSH, the following must be met:

  • An SSH server must be running on the remote machine.
  • The SSH port must be open in the remote machine firewall.
  • You must know the username and the password of the remote account. The account needs to have proper privileges for remote login.

If the above can’t be met, the connection to the remote machine will be established.

For example, to connect to a remote client by its hostname, you’ll use the commands below:

ssh example.com

If this is the first time you’re connecting to the remote host, you’ll get a similar message as below:

Output:
The authenticity of host 'example.com (192.168.1.2)' can't be established.
ECDSA key fingerprint is SHA256:9BgdTs*SLo}^e-EGMJ,1+RlHwVyYruOXK%NCDI2fj;.
Are you sure you want to continue connecting (yes/no)?

You must accept before connection will be established

Type yes to connect..

Each host stores a unique fingerprint of computer they connect to…

To establish connection using a different username, you can use the command below:

Example:

ssh username@example.com

or

ssh -l username example.com

If you do not specify a username when using the ssh command, the command automatically uses the logged in username for the connection..

By default, if you do not specify a port when using the ssh command, it will try connecting to its default communication port 22.

To specify a different and unique port, use the commands below:

Example:

ssh -p 1234 username@example.com

Assuming port 1234 is opened on your firewall, connection will be established over the given port..

To specify a different port number on the SSH server, open its configuration file ( /etc/ssh/sshd_config ) and edit the highlighted line:

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Port 1234
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

Save the file and restart the SSH server..

Many other server settings can be configured to establish even more secured connection..

For example, you can enable Public Key Authentication where cryptographic keys are generated to use for authentication instead of password.. The client generates a key pair, sends its public key to the server to store for future authentication..

To enable this, open the server configure file /etc/ssh/sshd_config

Then enable the lines below and save.

PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no

Save the file and exit

Restart SSH server:

sudo systemctl restart ssh

On the client computer, you can use the commands below to generate a key pair..

ssh-keygen -t rsa -b 4096 -C "admin@example.com"

You’ll be prompted to type a passphrase.. it’s up to use whether you want to use a passphrase.. In most cases, you won’t want to use it.

Once a key pair is generated on the client computer, you can use the commands below to export the client public key to the server.. This ensures that client and server to establish key authentication.

ssh-copy-id username@example.com

Enter the remote user password, and the public key will be appended to the remote user authorized_keys file..

You’ll want to make sure the client public key is in the server authorized_keys file before turning on key-based authentication.

With SSH, you can also use local and remote port forwarding.. Local port forwarding is where a SSH client connection is forwarded to a SSH host, before forwarding to a destination..

Remote port forwarding is the opposite of local port forwarding..

That’s it!

Conclusion:

This post shows you how to use the ssh command on Ubuntu to securely establish secure Secure Shell (SSH) communication to a remote host computer.

If you find any error above, please comment below to alert us..

You may also like the post below:

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.