Set Up FTP and SFTP Servers on Linux: A Secure, Step-by-Step Guide

Set Up FTP and SFTP Servers on Linux: A Secure, Step-by-Step Guide

Protect your file transfers with a practical, security-focused, step-by-step guide that teaches you how to set up SFTP server on a Linux VPS, covers FTP/FTPS differences, and offers production-ready deployment recommendations.

File transfer remains a core requirement for many webmasters, developers, and system administrators. While several protocols exist, FTP and SFTP are the most commonly used mechanisms for moving files between clients and Linux servers. This article provides a practical, security-focused, step-by-step guide for setting up both FTP and SFTP on a Linux VPS, highlights their underlying principles, compares their strengths and weaknesses, and offers deployment recommendations for production environments.

Understanding the basics: FTP, FTPS and SFTP

Before diving into setup, it’s important to understand protocol differences:

  • FTP (File Transfer Protocol) is an older protocol that operates on separate control (port 21) and data channels. By default, it transmits credentials and data in cleartext.
  • FTPS is FTP over SSL/TLS. It adds encryption to FTP sessions and supports both implicit (typically port 990) and explicit (AUTH TLS on port 21) modes.
  • SFTP (SSH File Transfer Protocol) is an entirely different protocol that operates over an SSH connection (usually port 22). It provides encryption, integrity, and strong authentication (passwords or keys).

Given modern security requirements, SFTP is generally recommended for secure file transfer due to its simplicity and native SSH integration. FTPS can be used where FTP compatibility is needed with encrypted channels. Classic FTP without encryption should be avoided on public networks.

Common application scenarios

Typical uses for FTP/SFTP on a Linux VPS include:

  • Website deployments (uploading static assets, templated files).
  • Automated backups and synchronization between systems.
  • Exchanging files with partners or customers who require direct upload/download access.
  • CI/CD pipelines that need secure artifact transfer.

Choice of protocol depends on client compatibility, automation requirements, and security policy. If client systems support SSH keys and you control the environment, SFTP with key-based authentication is often the best balance of security and operational simplicity.

Preparing your Linux VPS

These instructions assume a modern Linux distribution (Debian/Ubuntu or CentOS/RHEL). Start with system updates and basic hardening:

  • Update packages: sudo apt update && sudo apt upgrade or sudo yum update.
  • Create a dedicated user or group for file transfers if you want to isolate access.
  • Ensure SSH and firewall services are installed and manageable via systemctl.

If you are using a VPS provider such as USA VPS, verify network access, firewall rules, and snapshot/backup options before making production changes.

Setting up SFTP (recommended)

The SFTP setup leverages OpenSSH, which is typically preinstalled. We’ll configure an isolated chrooted SFTP environment with optional key-based authentication.

1. Create group and users

Create a group for SFTP users and a user account that will be chrooted.

  • sudo groupadd sftpusers
  • sudo useradd -m -G sftpusers -s /sbin/nologin sftpuser
  • sudo passwd sftpuser

Important: For chroot to work securely, the chroot directory must be owned by root and not writable by the chrooted user.

2. Directory layout and permissions

  • sudo mkdir -p /home/sftpuser/uploads
  • sudo chown root:root /home/sftpuser
  • sudo chmod 755 /home/sftpuser
  • sudo chown sftpuser:sftpusers /home/sftpuser/uploads

This pattern keeps the root of the chroot owned by root while giving write permissions to a subdirectory for uploads.

3. Configure sshd for SFTP-only access and chroot

Edit /etc/ssh/sshd_config and add at the end:

  • Subsystem sftp internal-sftp
  • Match Group sftpusers
  •     ChrootDirectory /home/%u
  •     ForceCommand internal-sftp
  •     X11Forwarding no
  •     AllowTcpForwarding no

Then restart SSH:

  • sudo systemctl restart sshd

This configuration forces members of sftpusers into their home directories using the internal SFTP server and prevents shell access, port forwarding, and X11 forwarding.

4. Key-based authentication (recommended)

Generate an SSH key pair on the client (ssh-keygen) and copy the public key to the server:

  • sudo mkdir -p /home/sftpuser/.ssh
  • sudo chown sftpuser:sftpusers /home/sftpuser/.ssh
  • sudo chmod 700 /home/sftpuser/.ssh
  • sudo nano /home/sftpuser/.ssh/authorized_keys
  • Paste the public key, then:
  • sudo chown sftpuser:sftpusers /home/sftpuser/.ssh/authorized_keys
  • sudo chmod 600 /home/sftpuser/.ssh/authorized_keys

Disable password authentication if you only want key-based logins (edit /etc/ssh/sshd_config):

  • PasswordAuthentication no
  • ChallengeResponseAuthentication no

Then restart SSH.

5. Firewall and testing

  • Open port 22 (or your custom SSH port) in your firewall: sudo ufw allow 22/tcp or appropriate firewalld commands.
  • Test from a client: sftp sftpuser@your_server_ip or use an SFTP client such as FileZilla with key authentication.

Troubleshoot by checking /var/log/auth.log (Debian/Ubuntu) or /var/log/secure (CentOS) and verifying permissions.

Setting up FTPS (vsftpd) when FTP compatibility is required

vsftpd is a popular FTP server with FTPS support. Below are installation and secure configuration steps for Debian/Ubuntu; adapt package manager commands for other distros.

1. Install vsftpd

  • sudo apt install vsftpd
  • sudo systemctl enable –now vsftpd

2. Generate SSL certificate

  • sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/vsftpd.key -out /etc/ssl/certs/vsftpd.crt

Use a certificate signed by a trusted CA for production, or a self-signed certificate for internal use.

3. Configure vsftpd for FTPS (explicit TLS)

Edit /etc/vsftpd.conf with secure settings:

  • listen=YES
  • anonymous_enable=NO
  • local_enable=YES
  • write_enable=YES
  • chroot_local_user=YES
  • allow_writeable_chroot=YES # only if you understand implications
  • ssl_enable=YES
  • rsa_cert_file=/etc/ssl/certs/vsftpd.crt
  • rsa_private_key_file=/etc/ssl/private/vsftpd.key
  • ssl_ciphers=HIGH
  • require_ssl_reuse=NO # fixes some client compatibility issues
  • ssl_tlsv1=YES
  • ssl_sslv2=NO
  • ssl_sslv3=NO
  • pasv_enable=YES
  • pasv_min_port=40000
  • pasv_max_port=40100

Restart vsftpd and open ports 21 and the passive port range in your firewall. Also configure NAT or port forwarding if VPS is behind NAT.

4. Security considerations

  • Prefer explicit FTPS over implicit; it’s easier to work with firewalls and more standardized.
  • Disable insecure FTP (no SSL) by setting ssl_enable=YES and refusing non-encrypted sessions if possible.
  • Use strong certificates and enforce strong ciphers. Periodically review and update TLS settings to match best practices.

Comparing SFTP and FTPS — pros and cons

Key tradeoffs:

  • SFTP
    • Pros: Single port (22), easier firewall/NAT traversal, strong SSH-based authentication (keys), simpler to script, better integration with SSH-based access policies.
    • Cons: Requires SSH access management; some legacy FTP clients don’t support it.
  • FTPS
    • Pros: Maintains FTP semantics, compatible with existing FTP-centric workflows and clients, explicit TLS can be negotiated on port 21.
    • Cons: Multiple ports (control + passive data range) complicate firewalls and NAT, certificate management required, historically trickier to configure securely.

For most modern deployments, SFTP provides superior operational simplicity and security. FTPS remains relevant when interoperability with legacy FTP-only systems is required.

Operational best practices and hardening

To keep your file transfer services secure and reliable, follow these recommendations:

  • Use strong authentication: prefer SSH keys for SFTP and TLS certificates for FTPS.
  • Implement least privilege: chroot users and restrict file system permissions to necessary directories.
  • Monitor logs and set up alerts for failed logins or abnormal activity.
  • Keep software up-to-date and apply security patches promptly.
  • Harden SSH: use non-standard ports if desired, disable root login, and rate-limit or block repeated failed attempts (fail2ban).
  • Restrict network access with firewall rules and consider allowing only application IP ranges where possible.
  • Use automation and configuration management (Ansible, Puppet, etc.) for reproducible, auditable setups on multiple VPS instances.

Choosing the right VPS and configuration suggestions

When selecting a VPS for hosting file transfer services, consider:

  • Network throughput and bandwidth caps — frequent large file transfers require higher throughput.
  • Disk performance and IOPS — use SSD-backed storage for better upload/download performance.
  • Snapshot and backup features to recover user data in case of accidental deletion.
  • Geographic location — choose a data center near your users to reduce latency.
  • Security features offered by the provider, such as private networking, DDoS protection, and firewall management.

If you need a reliable hosting provider, consider exploring options like USA VPS which provide flexible plans, SSD storage, and data centers that can be convenient for US-based audiences.

Summary

Both SFTP and FTPS have valid use cases, but for most modern environments SFTP is the preferred choice due to its simplicity, single-port operation, and robust authentication mechanisms. FTPS remains useful for compatibility with legacy FTP clients but requires more careful networking and certificate management. Regardless of the protocol you choose, focus on strong authentication, proper chroot and file permissions, firewall configuration, and continuous monitoring. Finally, pick a VPS with sufficient network and disk resources and the operational features you need to maintain availability and security. If you’re evaluating hosting options, you can review offerings such as USA VPS to match capacity and location to your deployment needs.

Fast • Reliable • Affordable VPS - DO It Now!

Get top VPS hosting with VPS.DO’s fast, low-cost plans. Try risk-free with our 7-day no-questions-asked refund and start today!