Last active
September 15, 2020 16:52
-
-
Save nf3/37fbf8916208498b95ffbf7fabfcb26f to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
#run with: | |
# wget --no-check-certificate https://gist.githubusercontent.com/nf3/37fbf8916208498b95ffbf7fabfcb26f/raw/addme_ssh.sh | |
# chmod +x ./addme_ssh.sh | |
# sudo bash -x addme_ssh.sh | |
# or | |
# sudo bash -x echo [PASSWORD] | addme_ssh.sh but this will put the password on the bashhistory | |
read -s -p "Password: " PASSWORD | |
USERNAME=nproctor | |
PUBKEYURL=https://raw.githubusercontent.com/nf3/vagrant-cent-salt/master/vagrant.pub | |
if [[ -n "$PASSWORD" ]]; then | |
yes | useradd -p $(openssl passwd -1 $PASSWORD) $USERNAME #creates the user with the password passed in | |
else | |
yes | useradd $USERNAME #creates the user with all y answers | |
chage -d 0 $USERNAME # this expires the password so that the 1st login will force it to be changed | |
fi | |
python3 -mplatform | grep -qi CentOS && usermod -aG wheel $USERNAME | |
python3 -mplatform | grep -qi Ubuntu && gpasswd -a $USERNAME sudo #add the user to sudo group in Ubuntu | |
python3 -mplatform | grep -qi Debian && gpasswd -a $USERNAME sudo #add the user to sudo group in Debian | |
mkdir /home/$USERNAME | |
mkdir /home/$USERNAME/.ssh | |
wget --no-check-certificate --output-document=/home/$USERNAME/.ssh/authorized_keys $PUBKEYURL | |
chmod 700 /home/$USERNAME/.ssh | |
chmod 600 /home/$USERNAME/.ssh/authorized_keys | |
chown -R $USERNAME:$USERNAME /home/$USERNAME | |
chsh -s /bin/bash $USERNAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment