Skip to content

Instantly share code, notes, and snippets.

@wsakaren
Created May 15, 2016 07:18
Show Gist options
  • Save wsakaren/b0940e4d8a870699dc34c6eb59c18548 to your computer and use it in GitHub Desktop.
Save wsakaren/b0940e4d8a870699dc34c6eb59c18548 to your computer and use it in GitHub Desktop.
add user linux with root access, empty ssh key and permissions all set
#!/bin/bash
if id "$1" >/dev/null 2>&1; then
echo "user exists"
else
echo "user does not exist, creating"
useradd -c "$1 last" $1 -m
fi
echo "$1 ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
su - $1 -c "mkdir .ssh"
su - $1 -c "chmod 700 .ssh"
su - $1 -c "touch .ssh/authorized_keys"
su - $1 -c "chmod 600 .ssh/authorized_keys"
su - $1 -c "chown -R $1:$1 .ssh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment