Skip to content

Instantly share code, notes, and snippets.

@takumakei
Last active April 22, 2024 03:55
Show Gist options
  • Save takumakei/f39a8f2daf15482fbb381f38aeba1c5c to your computer and use it in GitHub Desktop.
Save takumakei/f39a8f2daf15482fbb381f38aeba1c5c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# adduser.sh
#
# usage: curl -fsSL $URL | bash -s -- <github-user-name> [<user-name>]
#
set -eux -o pipefail
main() {
local github="$1"
local name="${2:-$github}"
cat <<EOF | sudo bash -sx
export LC_ALL=C
adduser "$name" --gecos "" --disabled-password
passwd -d "$name"
umask 077
mkdir "/home/$name/.ssh"
echo "# https://github.com/$github.keys" >> "/home/$name/.ssh/authorized_keys"
curl "https://github.com/$github.keys" >> "/home/$name/.ssh/authorized_keys"
chown -R "$name:$name" "/home/$name/.ssh"
usermod -aG sudo "$name"
usermod -aG docker "$name"
EOF
}
main "$@"
#!/usr/bin/env bash
#
# adduser.sh
#
# usage: curl -fsSL $URL | bash -s -- <github-user-name> [<user-name>]
#
set -eux -o pipefail
main() {
local github="$1"
local name="${2:-$github}"
cat <<EOF | sudo bash -sx
export LC_ALL=C
useradd -c "$github" "$name"
passwd -d "$name"
umask 077
mkdir "/home/$name/.ssh"
echo "# https://github.com/$github.keys" >> "/home/$name/.ssh/authorized_keys"
curl "https://github.com/$github.keys" >> "/home/$name/.ssh/authorized_keys"
chown -R "$name:$name" "/home/$name/.ssh"
usermod -aG sudo "$name"
usermod -aG docker "$name"
EOF
}
main "$@"
@takumakei
Copy link
Author

takumakei commented Apr 26, 2022

usage

adduser

curl -fsSL https://gist.githubusercontent.com/takumakei/f39a8f2daf15482fbb381f38aeba1c5c/raw/d78663cfcdf6c04a01f5ce0a69a49cab68594ef1/adduser.sh | bash -s -- $github [$name]

useradd

curl -fsSL https://gist.githubusercontent.com/takumakei/f39a8f2daf15482fbb381f38aeba1c5c/raw/d78663cfcdf6c04a01f5ce0a69a49cab68594ef1/useradd.sh | bash -s -- $github [$name]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment