This artcile will explain how to open SSH port 22 on Ubuntu 20.04 Focal Fossa Linux

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 20.04 Focal Fossa Linux with UFW
Open and delete port 22 ssh rules on Ubuntu 20.04 Focal Fossa Linux with UFW

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed or upgraded Ubuntu 20.04 Focal Fossa
Software ufw >= 0.36
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 20.04 Focal Fossa Linux step by step instructions

  1. Check the status of your firewall.
    # ufw status verbose
    Status: active
    Logging: on (low)
    Default: deny (incoming), allow (outgoing), disabled (routed)
    New profiles: skip
    
    Based on the above output all incomming ports are blocked by default.

    SUBSCRIBE TO NEWSLETTER
    Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


  2. Allow the SSH port 22 by using the ufw command:
    $ 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 bellow 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 we'll allow entire network subnet 192.168.0.0/24 execute:
    $ sudo ufw allow from 192.168.0.0/24 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 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/24 to any port ssh
    
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.