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

[html]
sudo yum install automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-devel make openssl-devel
[/html]

2.2 Compile and install s3fs:

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

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:

[html]
{
“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:::/*”]
}
]
}
[/html]

Download Credentials > Save

3.3 Switch to root

[html]
sudo su
[/html]

3.4 Store IAM credentials created previosuly:

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

3.5 Create mount point:

[html]
mkdir /mnt/
[/html]

3.6 Add mount point to fstab:

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

3.7 Mount bucket

[html]
mount -a
[/html]

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@matthewc424.sg-host.com.