{"id":51,"date":"2024-10-31T12:51:32","date_gmt":"2024-10-31T12:51:32","guid":{"rendered":"https:\/\/blog.eu.enginyr.ing\/?p=51"},"modified":"2024-11-12T12:39:22","modified_gmt":"2024-11-12T12:39:22","slug":"how-to-set-up-a-secure-ftp-server-on-linux-step-by-step-guide","status":"publish","type":"post","link":"https:\/\/www.serverspan.com\/en\/blog\/how-to-set-up-a-secure-ftp-server-on-linux-step-by-step-guide\/","title":{"rendered":"How to Set Up a Secure FTP Server on Linux: Step-by-Step Guide"},"content":{"rendered":"<p>Setting up an FTP (File Transfer Protocol) server on Linux can be essential for securely transferring files and sharing data between users or devices. However, traditional FTP is often considered insecure, as it transmits data in plain text. This guide will show you how to install and configure a secure FTP server on Linux using VSFTPD (Very Secure FTP Daemon), enabling encrypted file transfers, user permissions, and secure access controls.<\/p>\n<h3>What You\u2019ll Need<\/h3>\n<ul>\n<li><strong>A Linux server<\/strong> with a user account and sudo privileges<\/li>\n<li><strong>Basic command-line skills<\/strong><\/li>\n<li><strong>Internet access<\/strong> to install the required software packages<\/li>\n<\/ul>\n<h3>Step 1: Install VSFTPD<\/h3>\n<ol>\n<li><strong>Update the package index<\/strong> to ensure you have the latest repository list:<\/li>\n<pre><code>sudo apt update<\/code><\/pre>\n<li><strong>Install the VSFTPD package<\/strong> (for Debian\/Ubuntu systems):<\/li>\n<pre><code>sudo apt install vsftpd -y<\/code><\/pre>\n<p>For <strong>CentOS\/RHEL systems<\/strong>, use:<\/p>\n<pre><code>sudo yum install vsftpd -y<\/code><\/pre>\n<li><strong>Verify the installation<\/strong> by checking the VSFTPD version:<\/li>\n<pre><code>vsftpd -version<\/code><\/pre>\n<\/ol>\n<h3>Step 2: Configure Basic VSFTPD Settings<\/h3>\n<ol>\n<li><strong>Backup the default configuration file<\/strong>:<\/li>\n<pre><code>sudo cp \/etc\/vsftpd.conf \/etc\/vsftpd.conf.bak<\/code><\/pre>\n<li><strong>Open the configuration file<\/strong> in a text editor:<\/li>\n<pre><code>sudo nano \/etc\/vsftpd.conf<\/code><\/pre>\n<li><strong>Modify the settings<\/strong> as follows to enable secure and restricted access:<\/li>\n<ul>\n<li><strong>Disable anonymous FTP access:<\/strong><\/li>\n<pre><code>anonymous_enable=NO<\/code><\/pre>\n<li><strong>Allow local users to access FTP:<\/strong><\/li>\n<pre><code>local_enable=YES<\/code><\/pre>\n<li><strong>Enable uploading for local users:<\/strong><\/li>\n<pre><code>write_enable=YES<\/code><\/pre>\n<li><strong>Restrict each user to their home directory:<\/strong><\/li>\n<pre><code>chroot_local_user=YES<\/code><\/pre>\n<\/ul>\n<\/ol>\n<h3>Step 3: Secure FTP with SSL\/TLS<\/h3>\n<ol>\n<li><strong>Generate an SSL Certificate<\/strong> using OpenSSL:<\/li>\n<pre><code>sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout \/etc\/ssl\/private\/vsftpd.pem -out \/etc\/ssl\/private\/vsftpd.pem<\/code><\/pre>\n<p>Fill out the requested fields, as they will appear on the certificate.<\/p>\n<li><strong>Configure VSFTPD to use SSL<\/strong> by editing the configuration file again:<\/li>\n<pre><code>sudo nano \/etc\/vsftpd.conf<\/code><\/pre>\n<p>Add or modify the following lines to enable SSL:<\/p>\n<pre><code>ssl_enable=YES\nrsa_cert_file=\/etc\/ssl\/private\/vsftpd.pem\nrsa_private_key_file=\/etc\/ssl\/private\/vsftpd.pem\nforce_local_data_ssl=YES\nforce_local_logins_ssl=YES\nssl_tlsv1=YES\nssl_sslv2=NO\nssl_sslv3=NO<\/code><\/pre>\n<li><strong>Save and close the file<\/strong>, then <strong>restart VSFTPD<\/strong> to apply changes:<\/li>\n<pre><code>sudo systemctl restart vsftpd<\/code><\/pre>\n<\/ol>\n<h3>Step 4: Create FTP Users and Configure Permissions<\/h3>\n<ol>\n<li><strong>Create a dedicated FTP user<\/strong> and assign a password:<\/li>\n<pre><code>sudo adduser ftpuser\nsudo passwd ftpuser<\/code><\/pre>\n<li><strong>Restrict the user to their home directory<\/strong> for security:<\/li>\n<pre><code>sudo usermod -d \/home\/ftpuser ftpuser<\/code><\/pre>\n<li><strong>Set directory permissions<\/strong> so that only the FTP user can read and write files:<\/li>\n<pre><code>sudo chown ftpuser:ftpuser \/home\/ftpuser\nsudo chmod 755 \/home\/ftpuser<\/code><\/pre>\n<\/ol>\n<h3>Step 5: Configure Firewall to Allow FTP Traffic<\/h3>\n<p>If your server has a firewall enabled, you\u2019ll need to allow FTP traffic.<\/p>\n<p>For <strong>UFW (Ubuntu)<\/strong>:<\/p>\n<pre><code>sudo ufw allow 20\/tcp\nsudo ufw allow 21\/tcp\nsudo ufw allow 990\/tcp\nsudo ufw reload<\/code><\/pre>\n<p>For <strong>Firewalld (CentOS\/RHEL)<\/strong>:<\/p>\n<pre><code>sudo firewall-cmd --permanent --add-port=20-21\/tcp\nsudo firewall-cmd --permanent --add-port=990\/tcp\nsudo firewall-cmd --reload<\/code><\/pre>\n<h3>Step 6: Test the FTP Server<\/h3>\n<ol>\n<li><strong>Connect to your FTP server<\/strong> using a command-line FTP client or an FTP client like <strong>FileZilla<\/strong>.<\/li>\n<li>Enter the <strong>server IP address<\/strong>, username, and password to log in securely.<\/li>\n<li><strong>Verify the SSL connection<\/strong>:<\/li>\n<ul>\n<li>In FileZilla, set the <strong>\u201cEncryption\u201d option to Require explicit FTP over TLS<\/strong>.<\/li>\n<li>Confirm the secure connection by checking for a lock symbol or security notification.<\/li>\n<\/ul>\n<\/ol>\n<h3>Step 7: Enable Passive Mode (Optional)<\/h3>\n<p>For users behind a firewall or NAT, passive mode can facilitate smoother connections.<\/p>\n<ol>\n<li><strong>Add passive mode settings<\/strong> in the VSFTPD configuration file:<\/li>\n<pre><code>sudo nano \/etc\/vsftpd.conf<\/code><\/pre>\n<p>Add the following lines:<\/p>\n<pre><code>pasv_enable=YES\npasv_min_port=10000\npasv_max_port=10100<\/code><\/pre>\n<li><strong>Save and close the file<\/strong>, then <strong>restart VSFTPD<\/strong>:<\/li>\n<pre><code>sudo systemctl restart vsftpd<\/code><\/pre>\n<\/ol>\n<h3>Conclusion<\/h3>\n<p>Setting up a secure FTP server on Linux using VSFTPD ensures that files are safely transferred while maintaining user permissions and encryption. By following this guide, you\u2019ve established a solid FTP server configuration with SSL\/TLS encryption, firewall rules, and restricted user access, giving you a secure and efficient file transfer environment.<\/p>\n<p>Implement these steps to provide a secure and reliable FTP solution for your team or clients.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting up an FTP (File Transfer Protocol) server on Linux can be essential for securely transferring files and sharing data between users or devices. However, traditional FTP is often considered insecure, as it transmits data in plain text. This guide will show you how to install and configure a secure FTP server on Linux using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":52,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[148,158,151,153,157,155,152,156,154,160,159,150,146,149,147],"class_list":["post-51","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-file-transfer-linux","tag-free-ftp-setup","tag-ftp-firewall-configuration","tag-ftp-for-business","tag-ftp-over-ssl","tag-ftp-security","tag-ftp-user-permissions","tag-linux-file-sharing","tag-linux-ftp-setup","tag-linux-hosting-ftp","tag-linux-server-security","tag-linux-ssh-and-ftp","tag-secure-ftp-server","tag-setting-up-ftp-server","tag-vsftpd-guide"],"_links":{"self":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=51"}],"version-history":[{"count":0,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/51\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/52"}],"wp:attachment":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}