Skip to content

Instantly share code, notes, and snippets.

@hugoduraes
Created November 30, 2016 10:33
Show Gist options
  • Save hugoduraes/1a18fb458172eeaaba6d7173f2b559d6 to your computer and use it in GitHub Desktop.
Save hugoduraes/1a18fb458172eeaaba6d7173f2b559d6 to your computer and use it in GitHub Desktop.
Create user with root privileges and adds an SSH key to it

On the remote machine:

sudo su -
useradd <username> -m -s /bin/bash
echo '<username> ALL=(ALL:ALL) NOPASSWD:ALL' >> /etc/sudoers
mkdir -p /home/<username>/.ssh
touch /home/<username>/.ssh/authorized_keys
chown -R <username>:<username> /home/<username>/.ssh
chmod 700 /home/<username>/.ssh
chmod 600 /home/<username>/.ssh/authorized_keys

On the local machine:

ssh-keygen -b 4096 -f /path/to/privatekey -t rsa -N '' -o -a 500 -C "some description"
cat /path/to/publickey | ssh root@<ipaddress> "sudo tee -a /path/to/authorized_keys"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment