Last active
March 11, 2020 03:30
-
-
Save cauethenorio/bf6d049eae1d65baadc9a6b20d40a0da to your computer and use it in GitHub Desktop.
Script to create system users to run docker apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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