FTP on AWS Cloud using AWS S3

File Transfer is the most important task when you do any business within your multiple offices or with the client or vendors. There are many ways and means to do the File/data transfer across the each other. But all you need is the security and the convenience of the data transfer.

The convenient way to do the File/Data transfer is to configure the in-premises FTP server and share the credentials with vendor or Client to upload or download the data. There are many drawbacks in this old methodology, but it is the simplest solution available.

Many companies are using the Google Drive, Dropbox, and other online services to move the data, but the paying huge money for such services too. The options to avail the service from Dropbox enterprise or Google Drive enterprise is fixed space with the fixed price. The more you need, the more you need to pay for fixed size. This becomes cumbersome when it reaches the limit of the data storage.



Instead of using such paid service, if we use IaaS platform to configure our own Data Storage service, then it will be easy to manage and we need to pay as we use the data space. Here are the steps to configure the Ubuntu EC2 instance in AWS Cloud to provide the secure FTP solution and use the AWS S3 to store the data.

Step by Step method to configure the EC2 Instance for SFTP


Create an Instance on AWS

1. Login to your AWS Web console
2. Select the region which you want to use to configure the FTP Server.
3. Launch the micro instance (Ubuntu 16.04)
4. Use the minimum possible disk space (8GB) for OS
5. Allow port 22 only for incoming traffic
6. complete the launching process
7. Create a Bucket in AWS S3, which you want to use as FTP Server share point.

Create a User to allow access S3 from EC2 instance

1. Open IAM from AWS Console.
2. Create the new user by any name (without password) for programmatic access only.
3. Copy the 'Access Key' and 'Secret Key' for further use to allow access from FTP server.


Configure the Server for mount the created AWS S3 bucket

1. Login to your newly created EC2 instance
2. Update the ubuntu with;
$ sudo apt-get update

3. Install the s3fs to mount the S3 volume on system
$ sudo apt-get install s3fs

4. Create a password file on common location to access the AWS S3 from EC2 instance.
$ sudo vi /etc/passwd-s3fs
Save the Access key and Secret key in file as below format
Access_key:Secret_key

5. Create a folder on the server to mount the AWS S3 bucket.
$ sudo mkdir /usrdata

6. Verify the s3fs by mounting newly created S3 bucket on server
$ s3fs 's3-bucketname' /usrdata
$ df -h

7. Make sure you have the S3 bucket mounted on /usrdata folder and have read/write access on.

Configure the SFTP on instance


1. AWS EC2 instance is not allowed to access on port 22 without the shared key. Reset and allow the username/password option for ssh login.
* Yes this is less secure, but we will enhance the security for user level.

2. Edit file and allow passwordAuthenticate
$ sudo vi /etc/ssh/sshd_conf
PasswordAuthentication no (default)
Chance to
PasswordAuthentication yes

3. Add and configure the SFTP user by below command
$ sudo adduser 'username'
$ sudo passwd 'username'
Set the password for newly created user

3. Create a Folder inside the AWS S3 bucket for newly created user
$ mkdir /usrdata/'username'

4. Make the same username as owner for that folder
$ sudo chown username:username /usrdata/username

5. Edit the passwd file to set the Home Directory for newly created user
$ sudo vi /etc/passwd
find the newly created users (at bottom of the line in the file)
Change the home directory path to /usrdata/username


All Set to try first data transfer to SFTP. Use any FTP Client to try out the test of the SFTP server. Here we are using the FileZilla to connect to SFTP server.

* Open the Filezilla Application on your client computer
* Create new site and provide the IP address of your newly created EC2 instance
* Change the Protocol from FTP to SFTP (SSH File Transfer Protocol)
* Change the Logon Type to 'Ask for Password'
* Fill the 'username' you created for FTP access
* Once you click on 'Connect' it will prompt the password to connect to the FTP Server.



*** We can use the SSH key to connect and transfer the data to-from FTP server as well.



















Comments