Created
April 25, 2021 00:20
Create a user with sudo and ssh keys
This file contains hidden or 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
set -eux | |
user="$1" | |
github_user="$2" | |
mkdir -p "users" | |
rm -fr "users/${user}" | |
cp -R /etc/skel "users/${user}" | |
mkdir -p "users/${user}/.ssh" | |
chmod 700 "users/${user}/.ssh" | |
curl --fail "https://github.com/${github_user}.keys" > "users/${user}/.ssh/authorized_keys2" | |
chmod 600 "users/${user}/.ssh/authorized_keys2" | |
sudo useradd -m --skel "users/${user}" -G sudo "$user" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment