Simple instructions to install an SFTP server on Amazon Linux backed with S3 Storage.

1. Launch Amazon Linux 2 instance (micro is sufficient)

2. Install and configure s3fs:

2.1 Install dependencies

sudo yum install automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-devel make openssl-devel

2.2 Compile and install s3fs:

git clone https://github.com/s3fs-fuse/s3fs-fuse.git
cd s3fs-fuse
./autogen.sh
./configure
make
sudo make install

3. Create and Mount S3 Bucket:

3.1 Create S3 Bucket:

Through AWS GUI

3.2 Create User and policy for S3 Bucket:

Services > IAM > Add User > Give name and select programmatic access > Attach existing policies directly > Create Policy > Json:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:ListBucket"],
"Resource": ["arn:aws:s3:::"]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject"
],
"Resource": ["arn:aws:s3:::/*"]
}
]
}

Download Credentials > Save

3.3 Switch to root

sudo su

3.4 Store IAM credentials created previosuly:

echo accesskey:secretaccesskey > /etc/passwd-s3fs
chmod 600 /etc/passwd-s3fs

3.5 Create mount point:

mkdir /mnt/

3.6 Add mount point to fstab:

echo s3fs# /mnt/ fuse _netdev,rw,nosuid,nodev,allow_other,nonempty 0 0 >> /etc/fstab

3.7 Mount bucket

mount -a

4. Access the SFTP server with an SFTP client such as Filezilla. connect using instance user and pem key.

Credit goes to – https://winscp.net/eng/docs/guide_amazon_s3_sftp#creating_access_server

Written by Matt Cooper
Hi, I'm Matt Cooper. I started this blog to pretty much act as a brain dump area for things I learn from day to day. You can contact me at: matt@linuxtutorial.co.uk.