From 699498fe2c86e634582c3c2547eb883eeca79f9a Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Sat, 17 Sep 2022 14:50:24 +0200 Subject: [PATCH] feat: support configuring a shell for a user --- README.md | 6 +++--- start.sh | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 585beba..0d571bb 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ | --- | --- | --- | | `ROOT_AUTHORIZED_KEYS` | `/path/to/file` | Path to file that contains the public SSH keys that can be used for root user authentication. This file will be copied to `/root/.ssh/authorized_keys` | | `HOSTKEYS` | `/path/to/hostkey;...` | Specifies a (semi-colon separated list of) file(s) containing a private host key used by SSH. | -| `USERADD` | `{username}:{uid}:{gid};...` | Create user account(s) on startup | +| `USERADD` | `{username}:{uid}:{gid}:{shell};...` | Create user account(s) on startup | | `GROUPADD` | `{groupname}:{gid};...` | Create group account(s) on startup | | `BASE_DIR` | `/home` | Basedir used for user account creation (Default: `/home`) | @@ -28,7 +28,7 @@ $ docker run -it \ -v $(pwd)/jumpbox:/var/lib/jumpbox \ -e "ROOT_AUTHORIZED_KEYS=/var/lib/jumpbox/authorized_keys" -e "HOSTKEYS=/var/lib/jumpbox/ssh_host_ed25519_key;/var/lib/jumpbox/ssh_host_rsa_key" - -e "USERADD=jumpbox:1000:1000" + -e "USERADD=jumpbox:1000:1000:/bin/bash" -e "GROUPADD=jumpbox:1000" -p 1022:22 \ pommib/jumpbox:latest @@ -50,6 +50,6 @@ services: environment: ROOT_AUTHORIZED_KEYS: /var/lib/jumpbox/authorized_keys HOSTKEYS: /var/lib/jumpbox/ssh_host_ed25519_key;/var/lib/jumpbox/ssh_host_rsa_key - USERADD: jumpbox:1000:1000 + USERADD: jumpbox:1000:1000:/bin/bash GROUPADD: jumpbox:1000 ``` diff --git a/start.sh b/start.sh index 044ca12..6da2504 100755 --- a/start.sh +++ b/start.sh @@ -22,6 +22,7 @@ if [ ! -d "$BASE_DIR" ]; then fi # GROUPADD="group1:1000;group2:1001;group3:1002" +i="" while [ "$GROUPADD" != "$i" ] ;do i=${GROUPADD%%;*} GROUPADD="${GROUPADD#$i;}" @@ -32,20 +33,26 @@ while [ "$GROUPADD" != "$i" ] ;do groupadd --gid "$GROUP_GID" "$GROUP_NAME" done -# USERADD="user1:1000:1000;user2:1001:1000;user3:1002:1002" +# USERADD="user1:1000:1000:/bin/bash;user2:1001:1000:/bin/sh;user3:1002:1002:/bin/sh" +i="" +j="" while [ "$USERADD" != "$i" ] ;do i=${USERADD%%;*} USERADD="${USERADD#$i;}" USER_NAME=${i%%:*} - UID_GID="${i#$USER_NAME:}" - USER_UID="${UID_GID%%:*}" - USER_GID="${UID_GID#$USER_UID:}" + j="${i#$USER_NAME:}" + USER_UID="${j%%:*}" + j="${j#$USER_UID:}" + USER_GID="${j%%:*}" + j="${j#$USER_GID:}" + USER_SHELL=$j - useradd --home-dir "$BASE_DIR/$USER_NAME" --uid "$USER_UID" --gid "$USER_GID" "$USER_NAME" + useradd --home-dir "$BASE_DIR/$USER_NAME" --shell "$USER_SHELL" --uid "$USER_UID" --gid "$USER_GID" "$USER_NAME" done # HOSTKEYS="/var/lib/jumpbox/ssh_host_ed25519_key;/var/lib/jumpbox/ssh_host_rsa_key" +i="" if [ -n "$HOSTKEYS" ]; then while [ "$HOSTKEYS" != "$i" ]; do i=${HOSTKEYS%%;*}