Skip to content

Commit

Permalink
Merge branch 'jessie'
Browse files Browse the repository at this point in the history
  • Loading branch information
atmoz committed Nov 23, 2015
2 parents bc2cbde + 3c756a9 commit d7c9115
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.git
tests
README.md
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
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/*

# 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

Expand Down
47 changes: 38 additions & 9 deletions entrypoint
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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

0 comments on commit d7c9115

Please sign in to comment.