SFTP is otherwise known as Secure File Transfer Protocol. It is a network protocol that allows secure file moving advantage over a network. The main difference between FTP (File Transfer Protocol) and SFTP is that FTP sends data in plain text. The secure file transfer protocol on the other hand, encrypts the data that is being transferred. This gives a major advantage and makes secure file transfer protocol the widely chosen choice for safe data transmission. The main aspect of setting up, configuring, and managing secure file transfer protocol is to understand the port through which the data transfer happens.
What is the Default SFTP Port Number?
The default port number of the secure file transfer protocol is 22. Port 22 is the port used by Secure Shell (SSH). Secure file transfer protocol uses this same port to create a secure connection between client and server machines. When a secure file transfer protocol network connection is initiated, the machine connects to port 22 unless you have changed it.
Why is the SFTP Port Number Always 22?
SSH uses the port number 22, which is shared by SFTP. SSH is a protocol that provides a secure medium over an unsecure network. SFTP is built on SSH. Hence, SFTP uses the same port used by SSH. The integration between SSH and SFTP lets SSH gain advantage of the safety mechanisms of SSH like the latest encryption and authentication methods.
How to Change the SFTP Port Number?
Even if 22 is the default SFTP port number, it is possible to change the SFTP port number. Sometimes, changing the default secure file transfer protocol port number is recommended as well. Many automated attacks target well-established ports like 22. As a security measure, experts recommend changing the port to avoid malicious attacks. Let us see how you can change the default SFTP port number.
- Editing the SSH Config file: On the server, open the SSH configuration file. This configuration file is usually present at
.etc/ss/sshd_config
- Modifying the Port directive: Navigate to the “port directive” and change the value to the port number you like. If you want to change the port number to port 123, modify the value in the line to Port 123.
- Restarting the SSH service: Save the changes to the configuration file and restart the SSH service. To restart the SSH service, execute this command:
sudo systemctl restart sshd - Updating the Firewall rules: Allow traffic on the new port as well if you are using a firewall.
Update the SFTP Port Number in Client
Specify the port number in SFTP client when you connect to an SFTP server using a port other than port 22. To connect using the updated port number, follow this syntax:
Advantages of Changing SFTP Port Number
- Network policy: Some organizational policies specify that network administrators should allow some services to run on specific ports.
- More than one SSH service: If there are multiple SSH services running on the same machine, each service can be assigned a unique port number.
- Enhanced security: Malicious attackers also know that the default port number is 22. To reduce the risk of automated attacks, changing the port number is recommended.
Disadvantages of Changing the Port Number
There are both advantages and disadvantages of changing the default port number. If the new port is blocked by firewalls, the SFTP connection may fail. This will make remote file transfers impossible. Applications and scripts will be hard-coded to use port 22 as default port number. You have to run scripts to route them to use the updated port number. If the specified port is being used by another service, the service can fail or behave unpredictably. A little more effort and knowledge is required to change the port number and also to handle the consequences.
Wrapping Up
We hope you learn everything about the default SFTP port number (i.e., 22), its uses, why it is the default port number, how to change the port number, its advantages, and disadvantages. Understanding the protocol is important for system administrators, network administrators, and all Linux users to manage secure file transmissions. Utilize SFTP to ensure your file transfers are secure and encrypted.