0
0
Fork 0
mirror of https://github.com/atmoz/sftp.git synced 2024-11-17 12:51:33 -05:00

Support encrypted passwords and custom UID/GID

This commit is contained in:
Adrian Dvergsdal 2014-10-20 19:43:07 +02:00
parent db4bb8be25
commit c8541d6d67
3 changed files with 65 additions and 19 deletions

View file

@ -9,11 +9,12 @@ RUN apt-get update && \
# sshd needs this directory to run # sshd needs this directory to run
RUN mkdir -p /var/run/sshd RUN mkdir -p /var/run/sshd
# Add configuration and run script # Add configuration and script
ADD . /root ADD . /root
WORKDIR /root WORKDIR /root
RUN mv sshd_config /etc/ssh/sshd_config RUN mv sshd_config /etc/ssh/sshd_config && \
chmod +x run
EXPOSE 22 EXPOSE 22
CMD ["/bin/bash", "run"] CMD ["./run"]

View file

@ -1,36 +1,63 @@
sftp sftp
==== ====
Simple and easy to use SFTP server based on Debian Easy to use SFTP (*SSH File Transfer Protocol*) server.
Usage Usage
----- -----
- Define users and passwords in comma separated list with SFTP_USERS ("user1:pass1,user2:pass2"). - Define users and passwords in comma separated list with SFTP_USERS (syntax:
`user:pass[:e][:[uid][:gid]][,...]`).
- You must set custom UID and/or GID for your users if you want them to make
changes to your mounted volumes with permissions matching your host
filesystem.
- Mount volumes in user's home folder. - Mount volumes in user's home folder.
- The users are chrooted to their home directory, so you must mount the
The users are chrooted to their home folders, so it is important to mount the volumes in separate folders inside the user's home folder (/home/your-user/**your-folder**). volumes in separate directories inside the user's home directory
(/home/user/**mounted-directory**).
Examples Examples
-------- --------
Simple (one user and one folder): ### Single user and volume
``` ```
docker run \ docker run \
-e SFTP_USERS="foo:123" \ -e SFTP_USERS='foo:123' \
-v "/sftp/share:/home/foo/share" \ -v "/host/share:/home/foo/share" \
-p 2222:22 -d atmoz/sftp -p 2222:22 -d atmoz/sftp
``` ```
Multiple users and folders: ### Multiple users and volumes
``` ```
docker run \ docker run \
-e SFTP_USERS="foo:123,bar:abc" \ -e SFTP_USERS='foo:123,bar:abc' \
-v "/sftp/share:/home/foo/share" \ -v "/host/share:/home/foo/share" \
-v "/sftp/ebooks:/home/foo/ebooks" \ -v "/host/documents:/home/foo/documents" \
-v "/sftp/http:/home/bar/http" \ -v "/host/http:/home/bar/http" \
-p 2222:22 -d atmoz/sftp -p 2222:22 -d atmoz/sftp
``` ```
### Custom UID and GID
```
SFTP_USERS='foo:123:1001:100'
```
Only custom GID:
```
SFTP_USERS='foo:123::100'
```
### Encrypted password
Add `:e` behind password to mark it as encrypted:
```
SFTP_USERS='foo:$1$0G2g0GSt$ewU0t6GXG15.0hWoOX8X9.:e:1001:100'
```
Tip: you can use makepasswd to generate encrypted passwords:
`echo -n 123 | makepasswd --crypt-md5 --clearfrom -`

26
run
View file

@ -1,17 +1,35 @@
#!/bin/bash #!/bin/bash
# Add users # Add users (user:pass[:e][:[uid][:gid]][,...])
IFS=',' read -a users <<< "$SFTP_USERS" IFS=',' read -a users <<< "$SFTP_USERS"
for userData in "${users[@]}"; do for userData in "${users[@]}"; do
IFS=':' read -a data <<< "$userData" IFS=':' read -a data <<< "$userData"
user="${data[0]}" user="${data[0]}"
pass="${data[1]}" pass="${data[1]}"
useradd $user if [ "${data[2]}" == "e" ]; then
echo "$user:$pass" | chpasswd chpasswdParams="-e"
uid="${data[3]}"
gid="${data[4]}"
else
uid="${data[2]}"
gid="${data[3]}"
fi
useraddParams="-m -N"
if [ -n "$uid" ]; then
useraddParams="$useraddParams -o -u $uid"
fi
if [ -n "$gid" ]; then
useraddParams="$useraddParams -g $gid"
fi
useradd $useraddParams "$user"
echo "$user:$pass" | chpasswd $chpasswdParams
chown root:root /home/$user chown root:root /home/$user
chmod 755 /home/$user chmod 755 /home/$user
chown -R $user:users /home/$user/*
done done
# Run SSH # Run SSH