How To Setup FTP on AWS EC2 Ubuntu Instance

0
Setup FTP on AWS EC2 Ubuntu
FTP installation on AWS EC2 instance

Accessing the EC2 Ubuntu server for files upload or download is very complex for end users because it has no Cpanel or user interface installed within, so to upload/download any data to the EC2 server. In this article, I have explained step by step tutorial to setup FTP on AWS EC2 Ubuntu 20.04.

FTP Setup in Amazon EC2 instance Ubuntu 20.04

Step 1 : Install vsftpd

SSH to the AWS EC2 instance, here’s is how you can SSH to the EC2 instance.

$ sudo apt install vsftpd
$ sudo service vsftpd status
Setup FTP on AWS EC2 Ubuntu

Step 2 : Firewall Configuration

In the security groups inbound rules, you have to add following rules.

  • Port 22 for SSH
  • 20 to 21 for insecure FTP
  • Port 12000 – 12100

After adding this port to security group, now you have to check firewall status by following command

$ sudo ufw status

If it is show inactive, it’s okay. Now run following commands

$ sudo ufw allow 20:21/tcp
$ sudo ufw allow 12000:12100/tcp
$ sudo ufw enable

After firewall enable, check status again

$ sudo ufw status

It should be active now, and shows similar to the below.

Install FTP on AWS EC2 Ubuntu

Step 3 : User Creation

Now you have to create user with proper access rights. Let’s create a user with user name programmer_1.

$ sudo adduser programmer_1

As we will share only FTP access to the user (programmer_1), we have to modify SSH configuration file to prevent SSH access from the FTP user.

$ sudo vi /etc/ssh/sshd_config

Add the following line to the file

DenyUsers programmer_1

Save the file and restart SSH service by following command

$ sudo service sshd restart

Step 4: Access Rights

It completely depends upon the user rules, let’s give users only home directory access, what users will upload, update or download files there. I will create a home directory for the FTP user.

$ sudo mkdir /home/programmer_1/ftp_files

Now, set ownership of the newly created directory of the FTP user.

$ sudo chown nobody:nogroup /home/programmer_1/ftp_files

Added some more permission

$ sudo chmod a-w /home/programmer_1/ftp_files

Now we will create sub directory where FTP user will upload the files with ownership assign

$ sudo mkdir /home/programmer_1/ftp_files/uploads
$ sudo chown programmer_1:programmer_1 /home/programmer_1/ftp_files/uploads

Step 5: FTP server configuration

Before configuring the vsftpd configuration file located in /etc/vsftpd, take a backup of the file.

$ sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak
$ sudo vi /etc/vsftpd.conf

Now, change the pasv_address=x. x. x. x with the IP address of the EC2 Instance and listen=YES to remove the warning message from the FTP client.

listen=YES
listen_ipv6=NO
write_enable=YES
chroot_local_user=YES
local_umask=022
force_dot_files=YES

pasv_enable=YES
pasv_min_port=12000
pasv_max_port=12100
port_enable=YES

pasv_address=x.x.x.x
user_sub_token=$USER
local_root=/home/$USER/ftp

Now, restart the FTP server to make sure everything running perfectly with following commands.

$ sudo systemctl restart vsftpd
$ sudo service vsftpd status

If all working fine, you should see following.

● vsftpd.service - vsftpd FTP server
   Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-03-26 04:16:27 UTC; 3s ago
  Process: 26682 ExecStartPre=/bin/mkdir -p /var/run/vsftpd/empty (code=exited, status=0/SUCCESS)
 Main PID: 26693 (vsftpd)
    Tasks: 1 (limit: 1152)
   CGroup: /system.slice/vsftpd.service
           └─26693 /usr/sbin/vsftpd /etc/vsftpd.conf

Now, you can login with your FTP client such as filezilla or any other.

Conclusion

In this guide, you learned how to configure FTP on Amazon EC2 Server. If you are new to AWS and wondering about LAMP installation, here is the guide. If you have any questions, feel free to comment, I will answer all your questions.

LEAVE A REPLY

Please enter your comment!
Please enter your name here