Skip to content

Instantly share code, notes, and snippets.

@cauethenorio
Last active March 11, 2020 03:30
Show Gist options
  • Save cauethenorio/bf6d049eae1d65baadc9a6b20d40a0da to your computer and use it in GitHub Desktop.
Save cauethenorio/bf6d049eae1d65baadc9a6b20d40a0da to your computer and use it in GitHub Desktop.
Script to create system users to run docker apps
#!/usr/bin/env bash
set -e
# create system users to be run docker apps
# put this file in your /sbin dir and chmod +x it
# this script:
# - create users without pass
# - and them to the docker group
# - generate key and print public key (to be used as deploy key)
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 1 ] || die "1 argument required, $# provided"
adduser --disabled-password --gecos "" $1
usermod -G docker $1
sudo \
--set-home \
-u $1 \
bash -c 'ssh-keygen -t rsa -b 4096 -q -N "" -f ~/.ssh/id_rsa -C "$(whoami)@$(hostname)"'
sudo \
--set-home \
-u $1 \
bash -c 'cat ~/.ssh/id_rsa.pub'
echo -e "\nuser '$1' created."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment