Jun 26, 2023 4 min read

How to Enable and Use SSH on Ubuntu 22.04

Enable and Use SSH on Ubuntu 22.04 with our tutorial. SSH is a network protocol that provides a secure way to manage remote systems.

Enable and Use SSH on Ubuntu 22.04
Table of Contents


Before we begin talking about how to enable and use SSH on Ubuntu 22.04, let's briefly understand – What is SSH?

SSH, or Secure Shell, is a network protocol that provides a secure way to access and manage remote computers. It allows you to securely connect to a remote server over an unsecured network, like the internet. With SSH, you can remotely execute commands, transfer files, and tunnel network connections.

It encrypts all communication, ensuring confidentiality and integrity of data. SSH is widely used by system administrators, developers, and IT professionals for remote administration, remote login, and secure file transfers. It is a vital tool for maintaining the security of networked systems.

In this tutorial, you will learn how to install the SSH server on Ubuntu 22.04 using the apt package manager. We will also address a few FAQs on how toenable and use SSH on Ubuntu 22.04.

Advantages of SSH

  1. Secure Remote Access: SSH provides a secure method to access and manage remote computers over unsecured networks.
  2. Data Encryption: All communication through SSH is encrypted, ensuring the confidentiality and integrity of data.
  3. Authentication: SSH uses strong authentication methods, such as passwords or public key cryptography, to verify user identities.
  4. Port Forwarding: SSH allows for secure tunneling of network connections, enabling remote access to services running on remote servers.
  5. File Transfer: SSH supports secure file transfers between local and remote systems, making it easy to exchange files securely.

How to Enable SSH on Ubuntu 22.04

Installing the openssh-server package, which by default is available in the Ubuntu 22.04 repository, will enable SSH on the operating system.

sudo apt install openssh-server -y

After the openssh-server installation is finished, we will use the systemctl command to verify its status:

sudo systemctl status ssh

The SSH service is now functioning, so we'll use the ufw command to allow connections on the SSH port:

sudo ufw allow ssh

We'll enable and reload the ufw to save any changes:

sudo ufw enable && sudo ufw reload

How to Use SSH to Connect a Computer

Make sure the SSH servers are installed and operational on both machines before attempting to connect any other systems over SSH. Second, you need to know the hostname and IP address of the computer you want to connect to. For instance, in our situation, the system we want to connect to has the IP address and the hostname "linuxhint." To connect, we will run the following command:

ssh [email protected]

During the initial connection, it will ask you to confirm that you want to proceed, so type "y" and press the ENTER key, and then it will ask you for your password:

When the proper password is entered, our system connects to the new machine:

To confirm, we can list the contents of the system that is connected:


We will execute the exit command to stop the connection with the system connected using SSH:


FAQs to Enable and Use SSH on Ubuntu 22.04

How do I find the IP address of my Ubuntu 22.04 machine?

You can use the command ip addr show or ifconfig to find the IP address of your Ubuntu 22.04 machine.

How do I connect to my Ubuntu 22.04 machine using SSH?

From another computer, open a terminal or use an SSH client and enter the command ssh username@ip_address (replace username with your username and ip_address with the IP address of your Ubuntu machine).

How do I change the default SSH port on Ubuntu 22.04?

Open the SSH server configuration file using a text editor (e.g., sudo nano /etc/ssh/sshd_config) and modify the Port directive. Save the file and restart the SSH service for the changes to take effect.

How do I disable password authentication and use SSH keys on Ubuntu 22.04?

Edit the SSH server configuration file (e.g., sudo nano /etc/ssh/sshd_config) and set PasswordAuthentication to no. Generate an SSH key pair on your local machine and copy the public key to the remote Ubuntu machine's ~/.ssh/authorized_keys file.

How do I transfer files to and from my Ubuntu 22.04 machine using SSH?

You can use the scp command to securely transfer files between your local machine and the remote Ubuntu machine. For example, to copy a local file to the remote machine, use scp local_file username@ip_address:/path/to/destination.

How do I configure SSH to allow only specific users to connect on Ubuntu 22.04?

Open the SSH server configuration file (e.g., sudo nano /etc/ssh/sshd_config) and add the AllowUsers directive followed by the usernames of the allowed users. Save the file and restart the SSH service.

How do I view the SSH log on Ubuntu 22.04?

SSH logs are stored in the /var/log/auth.log file. You can view the log using a text editor or by using the tail command (e.g., sudo tail -f /var/log/auth.log).

How do I troubleshoot SSH connection issues on Ubuntu 22.04?

Check if the SSH service is running, ensure the correct IP address and port are used, verify firewall settings, and review SSH server configuration file for any errors. Checking the SSH log file can provide additional insights.


The client and host are two separate machines that can connect with one another using the SSH protocol. In this tutorial, we've set up the OpenSSH server on Ubuntu 22.04 and connected to a remote machine using it.

If you have any suggestions or queries, kindly leave them in the comments section.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.