Access Google Cloud Storage (GCS)via SFTP

SFTP to a GCS Bucket
What is GCS?
Object Storage provided by GCP which can scale infinitely.
What is SFTP ?
SFTP, or Secure File Transfer Protocol, is a secure file transfer protocol that uses secure shell encryption to provide a high level of security for sending and receiving file transfers.
In order to achieve SFTP access to GCS Bucket we need the below components
- Google Compute Engine (VM)
- GCS Fuse (rpm package)
- GCS Bucket
- SFTP Client (WinSCP/Filezilla)
- Create a GCE Virtual Machine with the below configuration
- OS = CentOs 7
- Identity and API access →Access Scopes →Set access for each API and give Full Access to Storage

Setting access for writing to GCS Bucket
- Create a GCS Bucket
- SSH into GCE and execute the below Command[as root account] to create a user for SFTP
- useradd -s /sbin/nologin sftpuser
- passwd sftpuser
- mkdir -p /var/sftp/upload
- chown sftpuser:sftpuser /var/sftp/upload
- chown root:root /var/sftp
- chmod 755 /var/sftp
- edit sshd_config as per the below instructions:
# find Subsystem sftp /usr/libexec/openssh/sftp-server and replace with Subsystem sftp internal-sftp
# add below lines to the end of the file
Match User sftpuser
ForceCommand internal-sftp
PasswordAuthentication yes
ChrootDirectory /var/sftp
AllowTcpForwarding no
X11Forwarding no
8. systemctl restart sshd
- Installing GCS Fuse [execute below commands]
sudo tee /etc/yum.repos.d/gcsfuse.repo > /dev/null <<EOF
[gcsfuse]
name=gcsfuse (packages.cloud.google.com)
baseurl=https://packages.cloud.google.com/yum/repos/gcsfuse-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOFsudo yum install gcsfuse
- Mount the GCS Bucket
sudo gcsfuse -o allow_other -uid=<uid of sftp user> -gid=<gid of sftp user> -file-mode=777 -dir-mode=777 <Bucket_Name>
- Access the Bucket using SFTP
Now use the External IP of the GCE to connect to the GCS as an SFTP location

SFTP to the GCE instance
putting objects into the upload folder will directly copy the objects to GCS Bucket