Skip to content

Instantly share code, notes, and snippets.

@bitdivine
Created April 25, 2021 00:20
Show Gist options
  • Save bitdivine/8ae40afd59a26c0899e0619c508a67d5 to your computer and use it in GitHub Desktop.
Save bitdivine/8ae40afd59a26c0899e0619c508a67d5 to your computer and use it in GitHub Desktop.
Create a user with sudo and ssh keys
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