Last active
April 6, 2020 07:58
-
-
Save GarimaDamani/3824a2d4e55b47903a8fc926f8b7fa75 to your computer and use it in GitHub Desktop.
Linux create user with sudo access. args expected username, group name and public key. Requires root access to provide sudo.
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
#!/bin/bash | |
echo "Adding user $1 with sudo access" | |
adduser --disabled-password --gecos "" $1 | |
cd /home/$1/ | |
mkdir .ssh | |
cd /home/$1/.ssh/ | |
touch authorized_keys | |
echo $2 >> authorized_keys | |
cd /home/$1/ | |
chown -R $1:opsworks .ssh/ | |
echo "$1 ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers | |
echo "$1 added. Please ask them to try to login now" | |
# Usage | |
# sudo chown +x linux_add_user.sh && ./linux_add_user.sh garimadamani "ssh-rsa AAA xxxxxxx.local" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment