Configuring a secure FTP (SFTP or FTPS) server is essential for secure file transfers. Below is a step-by-step guide to setting up a secure FTP server, considering best practices for security:
1. Choose the Type of Secure FTP Server
- SFTP: Uses SSH (Secure Shell) for encryption. No additional ports are needed, as it runs on port 22.
- FTPS: FTP over SSL/TLS. Requires additional configuration for certificates and may use multiple ports for passive connections.
2. Select an FTP Server Software
Popular options include:
– Windows: IIS FTP Server, FileZilla Server, or Cerberus FTP Server.
– Linux: OpenSSH (for SFTP), ProFTPD, vsftpd, or Pure-FTPd.
3. Install the Software
- Windows:
- Install IIS FTP or FileZilla Server.
- For SFTP, install OpenSSH Server (now included in Windows Server 2019 and later).
- Linux:
- Install OpenSSH for SFTP (
sudo apt install openssh-server
on Ubuntu orsudo yum install openssh-server
on CentOS/RHEL). - For FTPS, install vsftpd or another FTP server and configure SSL/TLS.
4. Configure SFTP Server (for Linux)
- Edit the SSH Configuration:
- Open the config file:
sudo nano /etc/ssh/sshd_config
- Ensure the following lines are present:
Subsystem sftp /usr/lib/openssh/sftp-server
- Restrict users to SFTP only (optional, for extra security):
Match User sftpuser
ForceCommand internal-sftp
ChrootDirectory /home/sftpuser
AllowTcpForwarding no
X11Forwarding no -
Restart SSH:
sudo systemctl restart sshd
-
Create SFTP Users:
- Create a user:
sudo adduser sftpuser
- Disable shell access (optional):
sudo usermod -s /sbin/nologin sftpuser
- Set ownership and permissions for the user’s directory:
sudo mkdir /home/sftpuser/files
sudo chown root:root /home/sftpuser
sudo chmod 755 /home/sftpuser
sudo chown sftpuser:sftpuser /home/sftpuser/files
5. Configure FTPS Server (vsftpd for Linux)
-
Install vsftpd:
sudo apt install vsftpd
-
Edit the Configuration File:
- Open the file:
sudo nano /etc/vsftpd.conf
- Update or add the following:
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
ssl_enable=YES
rsa_cert_file=/etc/ssl/certs/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.key
pasv_enable=YES
pasv_min_port=10000
pasv_max_port=10100 - Generate a self-signed SSL certificate (or use a certificate from a trusted CA):
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/vsftpd.key -out /etc/ssl/certs/vsftpd.pem
- Restart vsftpd:
sudo systemctl restart vsftpd
6. Configure Firewall
- Allow relevant ports:
- SFTP: Allow port 22.
sudo ufw allow 22
- FTPS: Allow port 21 (control channel) and passive port range (e.g., 10000-10100).
sudo ufw allow 21
sudo ufw allow 10000:10100/tcp
7. Secure the FTP Server
- Disable Root Login: Edit
/etc/ssh/sshd_config
and setPermitRootLogin no
. - Use Strong Passwords: Enforce password policies.
- Enable Logging: Configure the FTP server to log all connections and file transfers.
- Set Permissions: Restrict file system permissions for FTP users.
- Use Two-Factor Authentication (2FA): Add an extra layer of security for SFTP.
- Regular Updates: Keep the server and software patched against vulnerabilities.
8. Test the Configuration
- Use an FTP client like FileZilla, WinSCP, or Cyberduck to connect and verify:
- Use SFTP (port 22) or FTPS (port 21 with TLS/SSL).
- Test file uploads and downloads.
- Ensure logs are being generated.
9. Automate File Transfers (Optional)
- Use tools like
scp
,rsync
, or automated scripts withlftp
, Python, or PowerShell.
10. Monitor and Audit
- Use monitoring tools like Nagios, Zabbix, or Grafana to track server performance and usage.
- Regularly review logs for unauthorized access or suspicious activity.
By following these steps, you can set up and maintain a secure FTP server for encrypted file transfers while adhering to best practices for security.