How to Fix Port 22 (How to Open/Closed/Refused/Timed Out)


how to fix port 22

 

What is Port 22 Used For?

Port 22 is a widely known system port associated with the Secure Shell service. Port 22 is primarily used in networking applications.

  • The number 22 is given by the Internet Assigned Numbers Authority.
  • Port 22 can be used as an SCTP, TCP or UDP port for SSH service, file transfer, secure login and port forwarding.

TCP port 22 and UDP port 22differ in the communication pattern.TCP port 22 delivers data packets in the same order of sending. However, using the UDP port 22 may result in duplication, out of sequence or missing data packets.

 

Is Port 22 TCP or UDP?

Port 22 is primarily used as a UDP port because there are chances of a virus or a Trojan accessing the TCP port for communication.

Although TCP is slower, SSH uses the TCP port 22 as it guarantees reliable connection and delivery of data packets without getting lost.

 

How to Check if Port 22 is Open

Checking for an external port

  1. Open a web browser and go to the http://www.canyouseeme.org You can also use other websites or lookup for “open port check tool” using a search engine.
  2. Enter 22 in the Port to Check field.
  3. Press the Check Port button. If the port is free and open, a confirmation message is displayed. If not, you’ll see the appropriate error message stating that the service on the system’s IP address on port 22 could not be found.

 

Checking if the port is open on Windows

Telnet must be enabled to check for an open port on the Windows version.

 

Windows 10

  1. Type “windows features” in the search option of Windows.
  2. Click Turn Windows features on or off in the right panel.
  3. Check the Telnet Client checkbox and press OK.

 

Windows 7 and Windows Vista

  1. Click on the Start menu followed by Control Panel and then Programs.
  2. Click Turn Windows features on or off under Programs and features.
  3. Check the Telnet Client and Telnet Server checkboxes.
  4. Click OK.

After activating Telnet, proceed with the steps given below.

  1. Type “cmd” in the search bar.
  2. Click Command prompt in the right panel.
  3. Type “ipconfig” and press Enter. The router’s local address or the IP address is displayed next to the Default Gateway entry.
  4. Type “telnet” and press Enter.
  5. Type “open” followed by the above IP address and then 22.

In Windows 10, a message that asks you to press Enter or any key means that port 22 is open while a “Could not open connection” message indicates a closed port. In Windows 7 and Windows Vista, a blank screen indicates that the port is open.

 

Checking if the port is open on Mac

  1. Click the magnifying glass on the top right of the screen and type “terminal”.
  2. Type the netstat -nr | grep default command and press Return. The IP address of the router is displayed.
  3. Type nc-vz followed by the above IP address and port number 22
  4. Press the Return button.

If the port is open, you’ll get a Connection Succeeded message and a Connection Refused or Timed Out message if the port is closed.

 

How to check if port 22 is open on Linux

ss command

  1. Open the shell prompt or terminal application.
  2. Enter the sudo ss -tulpn command to list all ports in open status including port 22 if it’s open.

 

lsof command

  1. Open the shell prompt or terminal application.
  2. Enter the sudolsof-i:22

 

netstat command

  1. Open the shell prompt or terminal application.
  2. Enter the netstat -tulpn | grep LISTEN command to display a list of all open ports including port 22 if it’s open.

 

nmap command

  1. Open the shell prompt or terminal application.
  2. Enter one of the following commands.
  • sudonmap -sU -0 <<local host or system IP address>> (to list all open UDP ports including port 22 if it’s open.)
  • sudonmap -sT -0<<local host or system IP address>> (to list all open TCP ports including port 22 if it’s open.)
  • sudonmap -sTU -0 <<local host or system IP address>> (to list all open TCP and UDP ports including port 22 if it’s open.)

 

How to Check if Port 22 is Blocked by your ISP

Telnet should be active to check if port 22 is blocked by ISP. Once this is ensured, you can enter the command telnet <<yourdomain.com>> 22 (yourdomain.com represents the website to be checked for port 22 blocking.) to check if it’s blocked.

 

Checking port 22 in Windows

  1. Click on Start menu followed by Run.
  2. Type “cmd” and press Enter to open the command prompt.
  3. Enter the above-mentioned telnet command.

 

Checking port 22 in Mac OS

  1. Click on Mac HD followed by Applications and then Utilities. This opens the Terminal.
  2. Enter the above-mentioned telnet command.

 

Checking port 22 in Linux

  1. Open the Terminal emulator.
  2. Enter the above-mentioned telnet command.

You’ll get a message saying connection refused if port 22 is blocked by ISP.

 

How to Make Port 22 Listen

  1. Ensure that openssh-server is installed. You can use apt-get install openssh-server install command for the installation.
  2. Start running the ssh server running using the service ssh restart
  3. Check the status of the openssh-server using the systemctl status ssh
  4. Resolve the errors if any and restart the ssh server using the command given in Step 2.

Check for listening port 22and stop something else from listening on port 22 by executing the commands given below.

  • sudo netstat -plnt | grep ‘:22’
  • sudo service ssh stop

 

How to open port 22 on TP-Link router

For a wireless TP-Link router, follow the steps below on the Web management page of the router.

  1. Open a browser window and enter the router’s IP address.
  2. Enter the login credentials on the login page.
  3. Click Forwarding followed by Virtual Servers.
  4. Press the Add New button and add the required details. Mention 22 in the Service Port field and set Status to Enabled.
  5. Press Save to confirm the inclusion.

 

How to Open Port 22 on Dlink router

  1. Type the default IP address 192.168.1.1 into your browser’s address bar and press Enter.
  2. Enter the D-Link router utility login credentials(‘admin’ for both username and password).
  3. Click the Advanced tab and select the Postforwarding option from the menu.
  4. Enter a name for the port 22 in the Name field.
  5. Select the TCP or UDP field depending on the protocol used by the port that will be opened and enter 22 in the appropriate field.
  6. Select a computer name from the ComputerName dropdown list. If the name is not available, you can enter it manually.
  7. Press the Add/Apply button to add the port details to the Active Port Forwarding rules.
  8. Press Reboot so that the router gets refreshed and open the above port.

 

How to Open Port 22 on Windows 7

  1. Click Start and select Control Panel followed by System and Security and then Windows Firewall.
  2. Click Advanced Settings in the left panel followed by Inbound Rules.
  3. Click New Rule under Actions in the right panel.
  4. Select the Port option.
  5. Type 22 in the Specific Local Ports box.
  6. Select Allow the Connection option.
  7. Select the checkbox for profiles that should follow the rules.
  8. Type a name for the port and press Finish.

 

How to Open Port 22 on Windows 8/Windows 10

  1. Click the Search icon and type Firewall (Windows 8)/Windows Firewall (Windows 10).
  2. Click Windows Firewall with Advanced…/Windows Defender Firewallfollowed by Advanced Settings to open the Windows Firewall with Advanced Security window.
  3. Click Inbound Rules in the left panel and choose the New Rule… action.

To open an outgoing traffic rule in Windows 10, click on Outbound Rules.

  1. Select the Port option.
  2. Select whether the rule applies to a TCP Port or a UDP port.
  3. Follow steps 6 to 9 given above for opening port 22 on Windows 7.

 

How to Open Port 22 on Mac

  1. Click Start followed by System Preferences.
  2. Click the Internet and Networking option followed by the Sharing icon to enable the SSHD (SSH server or daemon).
  3. Click Remote Login and login using the name and address shown below the Sharing window.

 

How to Fix Port 22 Not Connecting

  1. If the SSH service is down, check with the hosting provider for the reason. Alternatively, if you have a dedicated server or local host, execute the sudo service ssh restart command to start the service once again.
  2. Check the SSH port once again with the grep Port /etc/ssh/sshd_config command and attempt a reconnection with the correct credentials. You may also use the command to assign the SSH service to another port if port 22 has been blocked by the ISP.
  3. Check if the SSH port is closed because it’s not installed on the server you’re connecting to or the connection is blocked due to a firewall.

If the port is closed because of non-installation, the sudo apt install openssh-server command can help to resolve the problem. You may want to execute a Purge command before the installation. To overcome blocking, disable the blocking firewall by changing the settings of the destination port to ACCEPT.

 

Why is Port 22 Blocked?

 

Port 22 may be blocked because it’s not listening or outbound rules are set on the firewall.

  1. Check if ssh server is running using the netstat -ant Also, check for port listening by executing the netstat -ab | find “:22” command.
  2. Check if the firewall has outbound filters enabled and connect to some other SSH server.
  3. Turn the firewall on and set an exception for port 22.
  4. Check from an nmap/telnet host if port 22 is accessible.

 

Why is port 22 closed?

  1. Port closed during upgrade

A configuration error stops the sshd from running at the beginning itself because of a version mismatch of the openssl command or incompatibility of the version of installed packages. This can be resolved by executing the commands given below.

apt-get update

apt-get install opensslopenssh-server libssl1.0.0

apt-get install -f

 

  1. Maximum number of clients exceeded

The number of clients authenticated to access the SSH service at a time that is in the MaxStartups option has been exceeded. This number has to be revised for accessing the service.

 

Why is port 22 connection refused?

Some major reasons for refusal of port 22 connection and their fixes are the same as given in the “How to fix port 22 not connecting” section above.

Additionally, try doing the following.

  1. Check if many people are trying to access the server at a time by looking up the iptable rules. Often, only five new connections are allowed per minute. Also, try connecting after disabling iptables.
  2. Your computer has the same IP as that of another computer on the network. Getting the IP changed can help.

 

SSH connection to port 22 operation timed out

  1. Check if the IP address of the host is mentioned correctly.
  2. Verify if the network that you’re using supports connection to SSH port by pinging the host and using telnet command.
  3. Ensure that the firewall rules on the VPS are disabled or change the firewall settings.
  4. Check if SSH service is listening to port 22 or some other port.
  5. Debug the ssh connection from the client machine using the o ssh -vvvuser@host
  6. If the SSH server is running on a non-standard port, identify the appropriate port and run the ssh -p <<<non-standard port number>> hostname

 

Connection closed by 127.0.0.1 port 22

  1. Check the firewall and disable it if needed. Also, install the ssh daemon using the sudo apt-get install openssh-server
  2. Reassign or change the port number 22 to another number and add the details to the ~/.ssh/config file. Alternatively, use the -P option on scp or -p option on ssh to specify the revised port number.
  3. Check the /config/ssh folder in the drive for SSH keys and ensure their size is not 0B. If so, delete the keys and reboot the server to recreate them.
  4. Uninstall the antivirus on the system as it may be blocking the local server.

Recent Posts