Skip to content

Instantly share code, notes, and snippets.

@stilliard
Last active July 30, 2019 11:03
Show Gist options
  • Save stilliard/40243d63977139e1760dc04ea1aa81a7 to your computer and use it in GitHub Desktop.
Save stilliard/40243d63977139e1760dc04ea1aa81a7 to your computer and use it in GitHub Desktop.
New ssh user setup via github key

Set newusername as the account name you want the user to have on the server, & newusergithub as that persons github account name. This then takes their public key used with github and allows the user to login to the server via their ssh key.

newusername=bob
newusergithub=bobsgh

sudo useradd -m -d /home/$newusername -s /bin/bash $newusername
cd /home/$newusername/
sudo mkdir .ssh
sudo curl https://github.com/$newusergithub.keys | sudo tee .ssh/authorized_keys
sudo chmod 700 .ssh/
sudo chmod 600 .ssh/authorized_keys
sudo chown -R $newusername:$newusername .ssh/
sudo usermod -aG sudo $newusername    # optionally give sudo access to the user

The user is now setup with ssh access. Last thing to do is ssh in and set a password:

ssh IPHERE
passwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment