entrypoint.sh 728 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/sh
  2. set -e
  3. if [ ! -f "$SSHD_HOST_KEYS_DIR/rsa" ]; then
  4. ssh-keygen -t rsa -b 4096 -N '' -C '' -f "$SSHD_HOST_KEYS_DIR/rsa"
  5. fi
  6. if [ -z "$USERS" ]; then
  7. echo '$USERS is not set'
  8. exit 1
  9. fi
  10. IFS=','
  11. for USER in $USERS; do
  12. if ! id "$USER" 2>/dev/null >/dev/null ; then
  13. (set -x; adduser -D "$USER")
  14. # default after `adduser -D`: !
  15. # > User alice not allowed because account is locked
  16. # `passwd -u` sets an empty password,
  17. # so better insert '*' manually
  18. # https://unix.stackexchange.com/a/193131/155174
  19. sed -i "s/^${USER}:!:/${USER}:*:/" /etc/shadow
  20. fi
  21. done
  22. set -x
  23. sed -i "s/^AllowUsers .*/AllowUsers ${USERS//,/ }/" /etc/ssh/sshd_config
  24. exec "$@"