Table of Contents
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
- 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.
- Enter 22 in the Port to Check field.
- 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
- Type “windows features” in the search option of Windows.
- Click Turn Windows features on or off in the right panel.
- Check the Telnet Client checkbox and press OK.
Windows 7 and Windows Vista
- Click on the Start menu followed by Control Panel and then Programs.
- Click Turn Windows features on or off under Programs and features.
- Check the Telnet Client and Telnet Server checkboxes.
- Click OK.
After activating Telnet, proceed with the steps given below.
- Type “cmd” in the search bar.
- Click Command prompt in the right panel.
- Type “ipconfig” and press Enter. The router’s local address or the IP address is displayed next to the Default Gateway entry.
- Type “telnet” and press Enter.
- 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
- Click the magnifying glass on the top right of the screen and type “terminal”.
- Type the netstat -nr | grep default command and press Return. The IP address of the router is displayed.
- Type nc-vz followed by the above IP address and port number 22
- 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
- Open the shell prompt or terminal application.
- Enter the sudo ss -tulpn command to list all ports in open status including port 22 if it’s open.
lsof command
- Open the shell prompt or terminal application.
- Enter the sudolsof-i:22
netstat command
- Open the shell prompt or terminal application.
- Enter the netstat -tulpn | grep LISTEN command to display a list of all open ports including port 22 if it’s open.
nmap command
- Open the shell prompt or terminal application.
- 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
- Click on Start menu followed by Run.
- Type “cmd” and press Enter to open the command prompt.
- Enter the above-mentioned telnet command.
Checking port 22 in Mac OS
- Click on Mac HD followed by Applications and then Utilities. This opens the Terminal.
- Enter the above-mentioned telnet command.
Checking port 22 in Linux
- Open the Terminal emulator.
- 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
- Ensure that openssh-server is installed. You can use apt-get install openssh-server install command for the installation.
- Start running the ssh server running using the service ssh restart
- Check the status of the openssh-server using the systemctl status ssh
- 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.
- Open a browser window and enter the router’s IP address.
- Enter the login credentials on the login page.
- Click Forwarding followed by Virtual Servers.
- Press the Add New button and add the required details. Mention 22 in the Service Port field and set Status to Enabled.
- Press Save to confirm the inclusion.
How to Open Port 22 on Dlink router
- Type the default IP address 192.168.1.1 into your browser’s address bar and press Enter.
- Enter the D-Link router utility login credentials(‘admin’ for both username and password).
- Click the Advanced tab and select the Postforwarding option from the menu.
- Enter a name for the port 22 in the Name field.
- 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.
- Select a computer name from the ComputerName dropdown list. If the name is not available, you can enter it manually.
- Press the Add/Apply button to add the port details to the Active Port Forwarding rules.
- Press Reboot so that the router gets refreshed and open the above port.
How to Open Port 22 on Windows 7
- Click Start and select Control Panel followed by System and Security and then Windows Firewall.
- Click Advanced Settings in the left panel followed by Inbound Rules.
- Click New Rule under Actions in the right panel.
- Select the Port option.
- Type 22 in the Specific Local Ports box.
- Select Allow the Connection option.
- Select the checkbox for profiles that should follow the rules.
- Type a name for the port and press Finish.
How to Open Port 22 on Windows 8/Windows 10
- Click the Search icon and type Firewall (Windows 8)/Windows Firewall (Windows 10).
- Click Windows Firewall with Advanced…/Windows Defender Firewallfollowed by Advanced Settings to open the Windows Firewall with Advanced Security window.
- 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.
- Select the Port option.
- Select whether the rule applies to a TCP Port or a UDP port.
- Follow steps 6 to 9 given above for opening port 22 on Windows 7.
How to Open Port 22 on Mac
- Click Start followed by System Preferences.
- Click the Internet and Networking option followed by the Sharing icon to enable the SSHD (SSH server or daemon).
- Click Remote Login and login using the name and address shown below the Sharing window.
How to Fix Port 22 Not Connecting
- 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.
- 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.
- 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.
- Check if ssh server is running using the netstat -ant Also, check for port listening by executing the netstat -ab | find “:22” command.
- Check if the firewall has outbound filters enabled and connect to some other SSH server.
- Turn the firewall on and set an exception for port 22.
- Check from an nmap/telnet host if port 22 is accessible.
Why is port 22 closed?
- 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
- 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.
- 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.
- 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
- Check if the IP address of the host is mentioned correctly.
- Verify if the network that you’re using supports connection to SSH port by pinging the host and using telnet command.
- Ensure that the firewall rules on the VPS are disabled or change the firewall settings.
- Check if SSH service is listening to port 22 or some other port.
- Debug the ssh connection from the client machine using the o ssh -vvvuser@host
- 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
- Check the firewall and disable it if needed. Also, install the ssh daemon using the sudo apt-get install openssh-server
- 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.
- 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.
- Uninstall the antivirus on the system as it may be blocking the local server.