SFTP (Secure File Transfer Protocol) is a secure alternative to FTP, providing encrypted file transfer capabilities. Unlike FTP, which transmits data in plaintext, SFTP ensures that all data transferred between the client and server is encrypted, preventing unauthorized access and man-in-the-middle (MITM) attacks.
To configure SFTP, you’ll first need to ensure that SSH (Secure Shell) is installed and configured on the server. SSH serves as the foundation for SFTP, as SFTP relies on SSH for secure communication.
If SSH isn’t already installed on your server, you’ll need to install the OpenSSH server:
sudo apt update
sudo apt install openssh-server
Once installed, we should enable SSH and the service can be checked using:
sudo systemctl start ssh
sudo systemctl status ssh
Next, you will configure the SSH server to only allow SFTP access for specific users, and optionally, restrict them to specific directories (like their home directories).
To do this, we’ll modify the SSH configuration file (/etc/ssh/sshd_config).
sudo nano /etc/ssh/sshd_config
Subsystem sftp internal-sftp
# Restrict SFTP access to the user "sftpuser"
Match User sftpuser
ChrootDirectory /home/sftpuser
ForceCommand internal-sftp
AllowTcpForwarding no
sudo systemctl restart ssh
Once the configuration is complete, you can test the SFTP connection by trying to log in as the sftpuser:
sftp sftpuser@<server-ip>
This command connects to the server using SFTP, and it should prompt for the sftpuser’s password. After logging in, the user will only have access to their ChrootDirectory, typically /home/sftpuser, and will be unable to access other parts of the system.

One of the primary advantages of SFTP over FTP is encryption. In SFTP, both the command channel (where commands such as put or get are sent) and the data channel (where file transfers occur) are encrypted. This prevents eavesdropping and ensures that any credentials or files exchanged are not exposed to attackers.
Here’s how to demonstrate this:
sftp sftpuser@<server-ip>
Upon initiating the connection, you’ll notice that the entire communication, including login credentials and file data, is encrypted. While using a network monitoring tool like Wireshark, you’ll find that the data being transmitted is not readable or in plaintext.

In a real-world scenario, an attacker may attempt to capture traffic between the client and the server using a packet sniffer (like Wireshark). However, since SFTP uses SSH encryption, the captured packets will be unreadable, ensuring the confidentiality of the communication.