Skip to content

Commit

Permalink
Merge pull request #55 from panubo/feature/customise-user-shell
Browse files Browse the repository at this point in the history
add support for specifying user shell
  • Loading branch information
macropin authored Aug 27, 2020
2 parents 3f665ae + 924a133 commit 3df7210
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Configure the container with the following environment variables or optionally m

### General Options

- `SSH_USERS` list of user accounts and uids/gids to create. eg `SSH_USERS=www:48:48,admin:1000:1000`
- `SSH_USERS` list of user accounts and uids/gids to create. eg `SSH_USERS=www:48:48,admin:1000:1000:/bin/bash`. The fourth argument for specifying the user shell is optional
- `SSH_ENABLE_ROOT` if "true" unlock the root account
- `SSH_ENABLE_PASSWORD_AUTH` if "true" enable password authentication (disabled by default)
- `MOTD` change the login message
Expand Down
9 changes: 7 additions & 2 deletions entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,20 @@ if [ -n "${SSH_USERS}" ]; then
_NAME=${UA[0]}
_UID=${UA[1]}
_GID=${UA[2]}
if [ ${#UA[*]} -ge 4 ]; then
_SHELL=${UA[3]}
else
_SHELL=''
fi

echo ">> Adding user ${_NAME} with uid: ${_UID}, gid: ${_GID}."
echo ">> Adding user ${_NAME} with uid: ${_UID}, gid: ${_GID}, shell: ${_SHELL:-<default>}."
if [ ! -e "/etc/authorized_keys/${_NAME}" ]; then
echo "WARNING: No SSH authorized_keys found for ${_NAME}!"
else
check_authorized_key_ownership /etc/authorized_keys/${_NAME} ${_UID} ${_GID}
fi
getent group ${_NAME} >/dev/null 2>&1 || groupadd -g ${_GID} ${_NAME}
getent passwd ${_NAME} >/dev/null 2>&1 || useradd -r -m -p '' -u ${_UID} -g ${_GID} -s '' -c 'SSHD User' ${_NAME}
getent passwd ${_NAME} >/dev/null 2>&1 || useradd -r -m -p '' -u ${_UID} -g ${_GID} -s ${_SHELL:-""} -c 'SSHD User' ${_NAME}
done
else
# Warn if no authorized_keys
Expand Down

0 comments on commit 3df7210

Please sign in to comment.