In this tutorial you will learn how to deploy an SSH server on Ubuntu 20.04 Server/Desktop.
OpenSSH is the premier connectivity tool for remote login with the SSH protocol. It encrypts all traffic to eliminate eavesdropping, connection hijacking, and other attacks. In addition, OpenSSH provides a large suite of secure tunneling capabilities, several authentication methods, and sophisticated configuration options. Reference: https://www.openssh.com/
In this tutorial you will learn:
- How to install SSH Server
- How to change SSH server’s status
- How to open firewall rules to allow SSH incoming traffic
- How to connect to SSH Server remotely using the
ssh
command - How to change default SSH listening port
Software Requirements and Conventions Used
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa |
Software | OpenSSH |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Ubuntu 20.04 SSH Server step by step instructions
- Install the
openssh-server
in order to perform an installation of the SSH server on your Ubuntu 20.04 system:$ sudo apt install openssh-server
- Check the status. After the SSH server package installation the SSH server daemon should be up and running. To check the status of your SSH server execute the following command:
$ systemctl status sshd
To
start
,stop
andrestart
your SSH server use thesystemctl
command. For example the below command willrestart
the SSH server daemon:$ sudo systemctl restart ssh
-
Open ssh port 22 for an incoming traffic on your firewall:
$ sudo ufw allow ssh
- Enable the SSH server to start automatically during the boot.
$ sudo systemctl enable ssh
- Connect from a remote client to your SSH server. First, obtain an IP address of your SSH server. To do so execute the bellow
ip
command:$ ip a
In case you wish to connect to your SSH server over the internet you well need to obtain your external IP address:
$ echo $(wget -qO - https://api.ipify.org)
Lastly, connect to your SSH server remotely using the following ssh command syntax
ssh username@hostname-or-ip-address
.For example the bellow command will connect to the Ubuntu 20.04 SSH server with an IP address
192.168.1.112
as a userlinuxconfig
:$ ssh linuxconfig@192.168.1.112
- (optional) From security reasons it is recommended to change the default SSH port
22
to some other arbitrary port number above 1024. To do so edit the/etc/ssh/sshd_config
configuration file as an administrative sudo user.For example to change the defalut SSH port number from
22
to eg.8282
add the following line into the SSH config file:Port 8282
Once you have made the appropriate change open a firewall port to correspond with the new SSH port:
$ sudo ufw allow 8282/tcp
To apply the change to your SSH server use
systemctl
command to restart it:$ sudo systemctl restart ssh
In order to remotely connect to a specific SSH Server port number use the
-p
ssh command line option. Example:$ ssh -p 8282 linuxconfig@192.168.1.112