Skip to content

Instantly share code, notes, and snippets.

@elifiner
Last active April 4, 2024 12:02
Show Gist options
  • Save elifiner/1a5ed9cb06db1c0fc59a7426e4adc1b1 to your computer and use it in GitHub Desktop.
Save elifiner/1a5ed9cb06db1c0fc59a7426e4adc1b1 to your computer and use it in GitHub Desktop.
Create an non-root user on Ubuntu and set up sudo
#!/bin/bash
# This script will set up a non-root user on an empty Ubuntu box.
#
# Login as root and run:
#
# $ curl https://gist.githubusercontent.com/elifiner/1a5ed9cb06db1c0fc59a7426e4adc1b1/raw | sh -
USER=guru
adduser --disabled-password --gecos "" $USER
adduser $USER sudo
mkdir /home/$USER/.ssh
cp .ssh/authorized_keys /home/$USER/.ssh
chown -R $USER:$USER /home/$USER/.ssh
chmod 640 /etc/sudoers
echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
chmod 440 /etc/sudoers
echo "user $USER created."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment