Skip to content

Instantly share code, notes, and snippets.

@vijayparikh
Created August 14, 2018 20:17
Show Gist options
  • Save vijayparikh/05078c1976f6ab967912ee5b530adfaa to your computer and use it in GitHub Desktop.
Save vijayparikh/05078c1976f6ab967912ee5b530adfaa to your computer and use it in GitHub Desktop.
Setup an SFTP server through an Amazon AWS EC2 Instance
If you need to access/manage files stored on Amazon S3 bucket via SFTP, you can mount the bucket to a file system on a Linux server and access the files using the SFTP as any other files on the server.
Creating Access Server
Launch a new Amazon EC2 server. A basic Amazon Linux AMI (free tier eligible) server will generally suffice and the following instructions are tested on this distribution. Instructions for other distributions may differ.
To install the s3fs file system
- Login to your Linux server via SSH.
- Install dependencies:
sudo yum install automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-develmake openssl-devel
- Compile and install s3fs:
git clone https://github.com/s3fs-fuse/s3fs-fuse.git
cd s3fs-fuse
./autogen.sh
./configure
make
sudo make install
Mounting S3 Bucket to File System
- Switch to root:
sudo su
- Store security credentials that will be used to access the S3 bucket to /etc/passwd-s3fs:
echo <access-key-id>:<secret-access-key> > /etc/passwd-s3fs
chmod 600 /etc/passwd-s3fs
(Replace the <access-key-id> and <secret-access-key> with the actual values)
- Create mount point (example):
mkdir /mnt/<bucket>
- Add entry to fstab to mount the bucket:
echo s3fs#<bucket> /mnt/<bucket> fuse _netdev,rw,nosuid,nodev,allow_other,nonempty 0 0 >> /etc/fstab
(Replace the leading <bucket> with your bucket name and the /mnt/<bucket> with the mount point)
- Mount the bucket:
mount -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment