SSH is the primary method of remote access and administration on Ubuntu 22.04 Jammy Jellyfish and other Linux systems. SSH is a client-server service providing secure, encrypted connections over a network connection. After installing Ubuntu 22.04, it may be one of the first things you want to configure.
In this guide, we’ll go over the step by step instructions to install and configure SSH on Ubuntu 22.04. This will help you whether you just want to connect to remote systems via SSH or you want your own system to accept incoming connections as well.
In this tutorial you will learn:
- How to install SSH client and server on Ubuntu 22.04
- How to start and stop the SSH service
- How to allow SSH service through ufw firewall
- How to change the listening port of SSH server
|Category||Requirements, Conventions or Software Version Used|
|System||Ubuntu 22.04 Jammy Jellyfish|
|Software||OpenSSH server and client|
|Other||Privileged access to your Linux system as root or via the
|Conventions||# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to install SSH server Ubuntu 22.04
Follow the step by step instructions below to get SSH installed on your system and use it to initiate remote connections or accept incoming connections.
- Install the OpenSSH Server package for your system by executing the following command in terminal.
$ sudo apt install ssh
- The SSH service can be controlled through systemd. Use the following
systemctlcommands to configure and control the service.To start or stop the SSH server:
$ sudo systemctl start ssh AND $ sudo systemctl stop ssh
To restart the SSH server:
$ sudo systemctl restart ssh
To enable (make SSH start automatically at system boot), or disable the SSH server:
$ sudo systemctl enable ssh AND $ sudo systemctl disable ssh
- Check whether the SSH server is running by using the following
$ systemctl status ssh
- If you have the default Ubuntu firewall ufw enabled, you will need to execute the following command to allow SSH connections through the firewall.
$ sudo ufw allow ssh
- Connect from a remote client to your SSH server. First, obtain an IP address of your SSH server. To do so execute the below
$ 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)
Connect to Ubuntu 22.04 SSH server
After following the steps above, we can connect to our SSH server remotely by using the following ssh command syntax:
$ ssh username@hostname-or-ip-address
For example, the following command will connect to the Ubuntu 22.04 SSH server with an IP address
10.0.2.15 as the user
$ ssh email@example.com
Change default SSH port
This is optional, but for 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 default SSH port number from 22 to 7575 (random port number) open the SSH config file and make the following change.
- Edit the SSH config file with nano or your preferred text editor.
$ sudo nano /etc/ssh/sshd_config
- Then, change the
#Port 22line to
- Once you have made the appropriate change, open a firewall port to correspond with the new SSH port:
$ sudo ufw allow 7575/tcp
- To apply the change to your SSH server, use this
systemctlcommand to restart it:
$ sudo systemctl restart ssh
- In order to remotely connect to a specific SSH Server port number, use the
-pssh command line option. Example:
$ ssh -p 7575 firstname.lastname@example.org
In this guide, we saw how to install an SSH server on Ubuntu 22.04 Jammy Jellyfish Linux. We also learned how to control the service with
systemctl commands to start, stop, restart, enable, or disable the service. Lastly, we went over the steps to change the default SSH port, which is recommended for increased security. Remember to always use a good password for users on your system, so the accounts don’t get compromised through SSH.