Last active
August 31, 2020 14:48
-
-
Save takekazuomi/e18679d4771c129399180e962b1f96d5 to your computer and use it in GitHub Desktop.
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 | |
### | |
# Add User with SSH KeyAuth | |
# | |
# set -x | |
set -ue -o pipefail | |
export LC_ALL=C | |
function add-user() { | |
local github=$1 | |
local name=$2 | |
sudo adduser "$name" --gecos "" --disabled-password | |
sudo passwd -d "$name" | |
sudo mkdir "/home/$name/.ssh" | |
sudo chown "$name:$name" "/home/$name/.ssh" | |
sudo chmod 0700 "/home/$name/.ssh" | |
curl https://github.com/"$github".keys | sudo tee -a "/home/$name/.ssh/authorized_keys" | |
sudo chown "$name:$name" "/home/$name/.ssh/authorized_keys" | |
sudo chmod 0600 "/home/$name/.ssh/authorized_keys" | |
sudo usermod -aG sudo "$name" | |
sudo usermod -aG docker "$name" | |
} | |
function main() { | |
if [ -p /dev/stdin ]; then | |
local col1 | |
local col2 | |
while IFS=' ' read -r col1 col2; do | |
if [[ -n $col1 && -n $col2 ]]; then | |
add-user "$col1" "$col2" | |
fi | |
done | |
else | |
echo "No input given!" | |
fi | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment