How to set up a non-root sudo user in Ubuntu
One of the first things you should do when setting up a new server is set up a non-root sudo user.
To do this, connect to your server via SSH using the root user.
For windows, I highly suggest using Putty.
When you are connected to the server, issue the following command. You will be prompted for a password; please use something very secure and save it somewhere!
Add a new user and add it to the sudo user group
After confirming the password and adding the user, you can add it to the sudo group like this:
usermod -aG sudo username
Now switch to the sudo user with the following command:
su - username
You should now be able to use sudo commands! I recommend to now disable SSH access to root, and log in with the new sudo user next time.
Disable root login
You can disable root login via SSH by editing the config file.
But first, make sure you can log in with the new sudo user! Open another ssh connection (e.g. launch another instance of Putty) with the new username instead of root.
sudo nano /etc/ssh/sshd_config
Add the following or replace yes with no
And restart the SSH server
sudo systemctl restart sshd
Next? See how to add the user to a new or existing group.