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

Merge branch 'jessie'

This commit is contained in:
Adrian Dvergsdal 2015-11-23 13:46:34 +01:00
commit d7c9115796
3 changed files with 40 additions and 13 deletions

View file

@ -1,3 +1,2 @@
.git .git
tests tests
README.md

View file

@ -1,7 +1,6 @@
FROM debian:wheezy FROM debian:jessie
MAINTAINER Adrian Dvergsdal [atmoz.net] MAINTAINER Adrian Dvergsdal [atmoz.net]
# Install OpenSSH
RUN apt-get update && \ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get -y install openssh-server && \ DEBIAN_FRONTEND=noninteractive apt-get -y install openssh-server && \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
@ -9,9 +8,9 @@ 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
# Copy configuration and entrypoint script
COPY sshd_config /etc/ssh/sshd_config COPY sshd_config /etc/ssh/sshd_config
COPY entrypoint / COPY entrypoint /
COPY README.md /
EXPOSE 22 EXPOSE 22

View file

@ -1,17 +1,32 @@
#!/bin/bash #!/bin/bash
for users in "$@"; do function printHelp() {
IFS=':' read -a data <<< "$users" echo "Syntax: user:pass[:e][:[uid][:gid]]..."
user="${data[0]}" echo "Use --readme for information and examples."
pass="${data[1]}" }
if [ "${data[2]}" == "e" ]; then function printReadme() {
cat /README.md
}
function createUser() {
IFS=':' read -a param <<< $@
user="${param[0]}"
pass="${param[1]}"
if [ -z "$user" -o -z "$pass" ]; then
echo "You must at least provide a username and a password."
printHelp
exit 1
fi
if [ "${param[2]}" == "e" ]; then
chpasswdOptions="-e" chpasswdOptions="-e"
uid="${data[3]}" uid="${param[3]}"
gid="${data[4]}" gid="${param[4]}"
else else
uid="${data[2]}" uid="${param[2]}"
gid="${data[3]}" gid="${param[3]}"
fi fi
useraddOptions="--create-home --no-user-group" useraddOptions="--create-home --no-user-group"
@ -39,6 +54,20 @@ for users in "$@"; do
cat /home/$user/.ssh/keys/* >> /home/$user/.ssh/authorized_keys cat /home/$user/.ssh/keys/* >> /home/$user/.ssh/authorized_keys
chown $user /home/$user/.ssh/authorized_keys chown $user /home/$user/.ssh/authorized_keys
chmod 600 /home/$user/.ssh/authorized_keys chmod 600 /home/$user/.ssh/authorized_keys
}
if [[ -z $1 || $1 =~ ^--help$|^-h$ ]]; then
printHelp
exit 0
fi
if [ "$1" == "--readme" ]; then
printReadme
exit 0
fi
for user in "$@"; do
createUser $user
done done
exec /usr/sbin/sshd -D exec /usr/sbin/sshd -D