mrchaudhary/sftp-alpine

By mrchaudhary

Updated 7 months ago

alpine image for sftp service

Image
Databases & Storage
Operating Systems

26

This image will be used for hosting a SFTP container. it will require a script file as CMD mentioned below. #!/bin/bash

init.sh

Create the user for SFTP

useradd -rm -d /home/${SFTP_USER} -s /bin/bash -u 10001 ${SFTP_USER}

Set a password for the user

echo "${SFTP_USER}:${SFTP_PASS}" | chpasswd

Create necessary SSHD directories

mkdir -p /var/run/sshd

Generate SSH host keys

ssh-keygen -A

Ensure visibility of the profile

echo "export VISIBLE=now" >> /etc/profile

Setup directory for SFTP

mkdir -p ${SFTP_ROOT_DIR} chown root:root ${SFTP_BASE_DIR} chmod 755 ${SFTP_BASE_DIR} chown ${SFTP_USER}:${SFTP_USER} ${SFTP_ROOT_DIR}

Update SSH configuration to only allow SFTP

echo "Match User ${SFTP_USER}" >> /etc/ssh/sshd_config echo "ForceCommand internal-sftp" >> /etc/ssh/sshd_config echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config echo "ChrootDirectory ${SFTP_BASE_DIR}" >> /etc/ssh/sshd_config echo "PermitTunnel no" >> /etc/ssh/sshd_config echo "AllowAgentForwarding no" >> /etc/ssh/sshd_config echo "AllowTcpForwarding no" >> /etc/ssh/sshd_config echo "X11Forwarding no" >> /etc/ssh/sshd_config

Start the SSH daemon

exec /usr/sbin/sshd -D

Docker Pull Command

docker pull mrchaudhary/sftp-alpine