Skip to content

Instantly share code, notes, and snippets.

@CloudLinuxDeveloper
Last active April 22, 2024 05:51
Show Gist options
  • Save CloudLinuxDeveloper/ec801e51c0a3917555c01d8b064e7f9a to your computer and use it in GitHub Desktop.
Save CloudLinuxDeveloper/ec801e51c0a3917555c01d8b064e7f9a to your computer and use it in GitHub Desktop.
How to Installing (vsftpd) an FTP server on Ubuntu
vsftpd [Very Secure File Transfer Protocol Daemon] is a popular FTP server for Ubuntu. we will install and configure vsftpd on Ubuntu 18.04 / 19.10.
*** Install vsftpd
sudo apt update && sudo apt install vsftpd
*** Once installed, check the status of vsftpd
sudo service vsftpd status
*** Configure Firewall
sudo ufw allow OpenSSH
Open ports 20 and 21 for FTP, and ports 40000-50000 for passive FTP.also open port 990 for TLS.
sudo ufw allow 20/tcp
sudo ufw allow 21/tcp
sudo ufw allow 40000:50000/tcp
sudo ufw allow 990/tcp
***Enable the firewall if it isn’t already. Press y and ENTER if warned about disrupting the SSH connection.
sudo ufw enable
***Check the status of the firewall :
sudo ufw status
***Create FTP User
** Now create a new user that we will use to log into FTP. In this example, we will create a new user called ftpuser.
this user not fixed you can change .
sudo adduser ftpuser
*** Now Generate a strong password and keep it safe You can just press ENTER to each of these.
**Open the SSH config in nano.
sudo nano /etc/ssh/sshd_config
# Add the following to the bottom of the file replacing ftpuser with the user you want to deny SSH and SFTP access. You can add multiple users here separated by a single space. (To paste in nano, press the right mouse button) and save it.
# DenyUsers ftpuser
*** Restart the SSH service.
sudo service sshd restart
***Upload to a Web Server
Let’s set the folder above the document root as the home directory for ftpuser.
sudo usermod -d /var/www ftpuser
***This will allow our FTP user to write and alter files in the document root directory.
sudo chown ftpuser:ftpuser /var/www/html
***Upload to a Home Folder
sudo mkdir /home/ftpuser/ftp
***Set the ownership of the ftp directory to no nobody:nogroup.
sudo chown nobody:nogroup /home/ftpuser/ftp
sudo chmod a-w /home/ftpuser/ftp
*** we will create a new directory within /ftp where the user can view and upload files.
sudo mkdir /home/ftpuser/ftp/files
**Assign ownership of this directory to our new FTP user otherwise they will not be able to write to it.
sudo chown ftpuser:ftpuser /home/ftpuser/ftp/files
*** Configure vsftpd
Editing the config file, create a backup.
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak
**Open the config file in nano editor.
sudo nano /etc/vsftpd.conf
** Change/uncomment the u/m lines:
write_enable=YES
chroot_local_user=YES
chroot_local_user=YES
force_dot_files=YES
pasv_min_port=40000
pasv_max_port=50000
user_sub_token=$USER
local_root=/home/$USER/ftp
***save file and exit, press CTRL + X, press Y and then press ENTER and Restart vsftpd.
***Test FTP: Enter your server’s IP, your FTP username and password you created earlier, and click Quickconnect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment