Skip to content

Instantly share code, notes, and snippets.

@Kinuseka
Last active November 30, 2024 07:20
Show Gist options
  • Save Kinuseka/7f319c92ee6169b3ef678b83d7a86332 to your computer and use it in GitHub Desktop.
Save Kinuseka/7f319c92ee6169b3ef678b83d7a86332 to your computer and use it in GitHub Desktop.
Create sudo user
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
echo "[Warning] This is a password based SSH setup only"
read -p 'Username: ' user
echo "The rest of the details will now be taken care of the program"
read -p 'Continue? [Y/n]: ' usercont
if [ "$usercont" == "n" ]
then echo "Cancelled"
exit
fi
adduser $user
usermod -aG sudo $user
echo "Your VPS should be setup, next step will be yours"
echo "'sudo nano /etc/ssh/sshd_config'"
echo "if you want to change how ssh connects (e.g. disable root)"
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
read -p 'Username: ' user
read -p "ssh Public key for $user: " userpub
echo "The rest of the details will now be taken care of the program"
read -p 'Continue? [Y/n]: ' usercont
if [ "$usercont" == "n" ]
then echo "Cancelled"
exit
fi
adduser $user
usermod -aG sudo $user
su - $user -c "mkdir -p ~/.ssh"
su - $user -c "echo $userpub >> ~/.ssh/authorized_keys"
su - $user -c "chmod -R go= ~/.ssh"
su - $user -c "chown -R $user:$user ~/.ssh"
echo "Your VPS should be setup, next step will be yours"
echo "'sudo nano /etc/ssh/sshd_config'"
echo "if you want to change how ssh connects (e.g. disable root)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment