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
tests
README.md

View file

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

View file

@ -1,17 +1,32 @@
#!/bin/bash
for users in "$@"; do
IFS=':' read -a data <<< "$users"
user="${data[0]}"
pass="${data[1]}"
function printHelp() {
echo "Syntax: user:pass[:e][:[uid][:gid]]..."
echo "Use --readme for information and examples."
}
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"
uid="${data[3]}"
gid="${data[4]}"
uid="${param[3]}"
gid="${param[4]}"
else
uid="${data[2]}"
gid="${data[3]}"
uid="${param[2]}"
gid="${param[3]}"
fi
useraddOptions="--create-home --no-user-group"
@ -39,6 +54,20 @@ for users in "$@"; do
cat /home/$user/.ssh/keys/* >> /home/$user/.ssh/authorized_keys
chown $user /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
exec /usr/sbin/sshd -D