Ports which are also called channels are a crucial part of the transmission of data over the internet. For communication with servers using the internet, various programs use various ports. These ports have ranged from 1024 to 65535. In this post, we will cover the changing method for SFTP ports in Linux.
The content for the post is:
Let’s get the basic info of the SFTP port.
What is SFTP Port in Linux?
SFTP (SSH File Transfer Protocol) is a protocol that gives better security in transferring files between two hosts through an encrypted connection. It enables the user to perform different tasks on remote files and also for resuming file transfers. It has the same functionality as FTP protocols but with more security over the connection.
SFTP uses port 22 by default, while port 21 is used by FTP protocol. The thing that can be noticed between these two protocols is SFTP uses a single port for transferring files while the FTP protocol uses multiple ports dynamically. These channels are decided by the server and the client side automatically. So working with FTP protocols has some security threats as this is the entry point for attackers.
How to Change the SFTP Port in Linux?
Changing the SFTP protocols will increase the security of the connection. You can use the command with your desired port number to change it. Here, we will change the port from 22 to 4442:
$ sudo ufw allow 4442/tcp
The rules have been updated.
$ sudo firewall-cmd --permanent --zone=public --add-port=4442/tcp $ sudo firewall-cmd --reload $ sudo semanage port -a -t ssh_port_t -p tcp 4422
Now, open the “ssh_config” file and un-comment the “Port 22” line, and change the port number (4442). To do so, run the given command in the terminal:
$ sudo nano /etc/ssh/ssh_config
Search for the “Port 22” line, which is commented in most of the Linux operating systems:
The port has been changed from “22” to “4442”.
After that, restart the SSH service to update the new changes:
$ sudo systemctl restart ssh
The service has been restarted.
Note: If the above command does not work, use the following command (the usage may vary from distribution to distribution).
$ sudo systemctl restart sshd.service
To check if our port is “4442” running, use the given command:
$ ss -an | grep 4442
The above image shows that port 4442 is running.
How to Use the New SFTP Port?
To use the new SFTP port, you can use the following command with the remote hostname:
$ sftp -p 4442 username@remote_host
Or, if you are using a graphical user interface such as putty, Filezilla, etc. Change the port number when creating the SSH connection, as shown in the below image:
That’s how you can change the SFTP port.
To change the SFTP port in Linux, use the “sudo ufw allow 4442/tcp” command for setting the rules, and change the port in the “ssh_config” file. After that, restart the ssh service for the newly applied changes. This write-up has illustrated the method to change the SFTP port in Linux.