Skip to content

Instantly share code, notes, and snippets.

@Edison-Hsu
Last active December 12, 2017 06:24
Show Gist options
  • Save Edison-Hsu/4b0c7e7c515e6ac4fdf67e3031aba06b to your computer and use it in GitHub Desktop.
Save Edison-Hsu/4b0c7e7c515e6ac4fdf67e3031aba06b to your computer and use it in GitHub Desktop.
add_user.sh
#! /bin/sh
user=$1
group=${2:-wheel} # wheel/sudo
if [ -z "$user" ]; then
exit 1
fi
home=/home/$user
ssh_folder=$home/.ssh
# Use the adduser command to add a new user to your system.
adduser $user
passwd $user
# Use the usermod command to add the user to the sudo group.
usermod -aG $group $user
# create .ssh folder
cd $home
mkdir .ssh
chmod 700 .ssh
# create authorized_keys file
cd $ssh_folder
touch authorized_keys
chmod 600 authorized_keys
chown -R $user:$user $ssh_folder
# add key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment