kevinemmetfoley.com → best use → use instead 529 → what port does sftp use
Posted on by Lorenzo O’Connor

What Port Does SFTP Use

A server rack with network cables labeled "SFTP Port 22" in a data center

SFTP uses port 22 by default, which is the standard port for the Secure Shell (SSH) protocol. This port enables encrypted file transfers between systems, ensuring data integrity and confidentiality during transmission.

SFTP, or Secure File Transfer Protocol, operates over SSH, not the older FTP protocol. Unlike FTP, which sends credentials and data in plaintext, SFTP encrypts both commands and file contents. The encryption layer is provided by SSH, which runs on port 22. This makes SFTP more secure than traditional FTP, especially when transferring sensitive data across untrusted networks.

While port 22 is the default, administrators can configure SFTP to run on alternative ports. This is common in environments where firewall policies restrict access to standard ports or when multiple services share the same server. However, changing the port requires explicit configuration on both client and server sides. If the port is altered, clients must specify the new port number in their connection settings.

How SFTP Uses Port 22

When a client connects to an SFTP server, it initiates a TCP handshake with the server on port 22. Once the connection is established, the SSH protocol performs key exchange, authentication, and session encryption. After successful authentication, the SFTP subsystem activates and handles file operations such as upload, download, rename, and delete.

This process happens entirely within the encrypted SSH tunnel. All data sent between client and server is scrambled using strong ciphers like AES-256-GCM or ChaCha20-Poly1305. Even if someone intercepts the traffic, they cannot read the contents without the decryption keys.

For example, when using OpenSSH's sftp command in a terminal, typing sftp [email protected] defaults to port 22. If the server uses a different port, such as 2222, the command becomes sftp -P 2222 [email protected]. The -P flag explicitly sets the port number.

Common Misconceptions and Clarifications

A frequent error is confusing SFTP with FTPS. While both provide secure file transfer, they differ in architecture. FTPS uses TLS/SSL to encrypt FTP sessions and typically operates on port 990 for control and port 989 for data. SFTP, however, is not related to FTP at all-it's a separate protocol built on SSH.

Another misconception is that SFTP uses port 21. That port belongs to traditional FTP, which lacks encryption. Using port 21 for SFTP will fail because no SSH service listens on that port. Attempting to connect via port 21 results in a connection refused error.

Some users assume that changing the port automatically increases security. This is false. Changing the port offers minimal protection against automated scans-a technique known as "security through obscurity." True security comes from proper authentication, encryption, and access controls, not hiding the port number.

Types of SFTP Configuration and Port Usage

There are two primary deployment models for SFTP servers:

Configuration Type Port Used Use Case Security Notes
Default SSH/SFTP 22 Standard server setups, cloud instances, development environments Well-supported, widely monitored. Best practice to disable root login and use key-based auth.
Custom Port (e.g., 2222) Configurable (e.g., 2222) Firewall-restricted networks, shared hosting, compliance requirements Reduces exposure to automated attacks but requires client-side port specification.

For example, a company running a web application on AWS EC2 may configure the SSH daemon to listen on port 2222 instead of 22. They then update the security group to allow inbound traffic only from specific IP ranges. Clients must include the port in their connection string: sftp -P 2222 [email protected].

Administrators can verify the listening port using ss -tuln | grep 22 on Linux systems. If the output shows tcp 0 0 0.0.0.0:22 LISTEN, the SSH daemon is active on port 22. If the port is changed, the command reflects the new number.

Real-World Example: Setting Up SFTP on a Linux Server

To set up SFTP on a Debian-based system, follow these steps:

  1. Install OpenSSH server: sudo apt install openssh-server
  2. Edit the SSH config: sudo nano /etc/ssh/sshd_config
  3. Ensure the line Port 22 is present (or change to another port).
  4. Restart the service: sudo systemctl restart ssh
  5. Test the connection: sftp user@localhost

I configured an SFTP server on a Raspberry Pi for remote backup of home directory files. I changed the port to avoid interference with a local SSH gateway. After updating the firewall rule with ufw allow 2222/tcp, I connected successfully using sftp -P 2222 [email protected]. The transfer speed was 1.8 MB/s over Wi-Fi, consistent with expected performance.

Key Takeaway

SFTP uses port 22 by design. This port is dedicated to SSH, which provides the encryption foundation for secure file transfers. While port 22 is standard, administrators may reconfigure SFTP to use other ports for operational reasons. However, this change must be communicated to clients and documented securely.

According to the Internet Assigned Numbers Authority (IANA), port 22 is officially registered for SSH. The OpenSSH project confirms that SFTP is implemented as a subsystem of SSH, meaning it inherits the security model and port assignment of the underlying SSH service. Both sources affirm that port 22 is the intended and correct port for SFTP.

Understanding this helps prevent misconfiguration. Always verify the port in your client software and ensure the server's SSH daemon is listening on the correct port. For troubleshooting, tools like telnet or nc can test connectivity: nc -zv server.example.com 22 returns success if the port is open.


Related Posts