How to open ssh port 22 on Ubuntu 22.04 Jammy Jellyfish Linux

The SSH protocol operates on port 22 by default. In order to accept incoming connections on your SSH server, you will need to ensure that port 22 is allowed through the firewall.

In this tutorial, you will learn how to open SSH port 22 on Ubuntu 22.04 Jammy Jellyfish. The only prerequisite is that you must already have SSH installed. If you have not already installed it, see our guide on how to install SSH server on Ubuntu 22.04.

In this tutorial you will learn:

  • How to open ssh port 22
  • How to remove ssh port firewall rule
  • How to check current UFW rules for allowed/denied ports
Open and delete port 22 ssh rules on Ubuntu 22.04 Jammy Jellyfish Linux with UFW
Open and delete port 22 ssh rules on Ubuntu 22.04 Jammy Jellyfish Linux with UFW
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 22.04 Jammy Jellyfish
Software ufw
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

Open ssh port 22 on Ubuntu 22.04 Jammy Jellyfish Linux step by step instructions



  1. Start by opening a open a command line terminal and typing the following command to check the status of your firewall. Ubuntu uses ufw (uncomplicated firewall) by default, and it should already be installed.
    $ sudo ufw status verbose
    Status: active
    Logging: on (low)
    Default: deny (incoming), allow (outgoing), disabled (routed)
    New profiles: skip
    

    Based on the output above (bolded section), all incoming ports are blocked by default.

  2. Use the following command to Allow the SSH port 22:
    $ sudo ufw allow ssh
    

    Alternatively, it is possible to allow only a specific IP address or network subnet to connect via SSH port 22. The below example will allow IP address 192.168.1.2 to connect via port 22:

    $ sudo ufw allow from 192.168.1.2 to any port ssh
    

    In this example to allow an entire network subnet 192.168.0.0/16 execute:

    $ sudo ufw allow from 192.168.0.0/16 to any port ssh
    
  3. Check all currently defined UFW firewall rules:
    $ sudo ufw status verbose
    Status: active
    Logging: on (low)
    Default: deny (incoming), allow (outgoing), disabled (routed)
    New profiles: skip
    
    To                         Action      From
    --                         ------      ----
    22/tcp                     ALLOW IN    Anywhere                  
    22/tcp (v6)                ALLOW IN    Anywhere (v6)
    
  4. To delete your SSH defined rules simply execute the same commands you used to allow SSH port 22 and specify the delete option right after the ufw command. Examples:
    $ sudo ufw delete allow ssh
    $ sudo ufw delete allow from 192.168.1.2 to any port ssh
    $ sudo ufw delete allow from 192.168.0.0/16 to any port ssh
    


Closing Thoughts

In this tutorial, you learned how to open SSH port 22 on Ubuntu 22.04 Jammy Jellyfish Linux. You also saw how to allow specific IP addresses or networks, without allowing incoming SSH traffic from any host. Finally, you learned how to delete the firewall rules that were added previously, in case you need to change your settings again in the future.