Skip to content

Instantly share code, notes, and snippets.

@sieemma
Last active October 22, 2020 22:07
Show Gist options
  • Save sieemma/ff71f320bb6a46d24d6e3f2c9ff13306 to your computer and use it in GitHub Desktop.
Save sieemma/ff71f320bb6a46d24d6e3f2c9ff13306 to your computer and use it in GitHub Desktop.
Adding new user to your vps server
How to add a new user on a linux vps
# Log in to the vps server using the:
root username and
password
# After a successful login, start:
# In the next command, your_desired_username should be any username you want to give to your new user. Please, change it and do not
use "your_desired_username". My username is sieemma so I will do mine as "adduser sieemma". The most important part is your password. you can
press enter to skip the rest.
adduser your_desired_username
# Follow the on screen instructions by entering your:
password and confirming it.
# for the fields that you do not need, press enter to skip them.
apt-get update
apt-get install sudo
usermod -aG sudo your_desired_username
# To prevent unnecessary asking for passwords when performing certaing actions, you can do this to help it: Also, don't forget to change the 'username' to your newly created username.
sudo echo 'username ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/username-ALL-NOPASSWD
# if you get the error: sudo: unable to resolve host Nodehost: Invalid argument use the guide below to resolve it:
# Use this: https://gist.github.com/sieemma/4174f10c2cac0b50313b10afc317dd71
# You are done.
Try logging in with the new username and password in a new putty session.
Logging in to your vps using an ssh key.
mkdir ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys2
# Copy your public key derived from puttygen or any key generator as below:
ssh-rsa AAAAB3NzaC1yc2EA[...]Lg5whU0zMuYE5IZu8ZudnP6ds= myname@example.com
# Do not add anything apart from what is in the public key. In the above, it contains an email which is why you can find it in.
# Next,
ctrl + x then y
chmod 600 ~/.ssh/authorized_keys2
# Adding private key to your putty.
# open putty
Then go to SSH -> Auth and click on Browse:
# Browse your file system and select your previously created private key:
# Then go to putty again and click on Save to our profile. You can choose not to save the profile but you will have to go through the steps each time you want to login.
# Now we have attached the private key to our PuTTY profile.
As you can see, the public key is now used for authentication, and you are asked for the passphrase, use the one you used to encrypt the private keys.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment