Setting up a non-root user account
TL;DR
user=<your chosen username>
adduser $user
usermod -aG sudo $user
What
user=<your chosen username>
creates a Bash variable to hold your username string and make it easier to run the next commands
adduser $user
creates a new user using the username you chosen. $user
refers to the bash variable (in bash, a string starting with $
is perceived as a variable and gets substituted with the value of the variable before the whole command runs.
usermod -aG sudo $user
adds your new user to the sudo-ers group. That means that your new user can run root-priviledged commands by using sudo
.
sudo -l -U $user
shows what commands the $user can execute using sudo. If you ran usermod before, it should show something similar to the above. If not, it will state that the user does not have sudo priviledges.
Why
Working on your server (or any server for that mater) using the root account is very very dangerous. For starts, it's easy to wipe the whole system just by issuing a mistyped rm
command (personally I've done it once. I learned ever since!).
By using a normal user account, you KNOW when you are doing something potentially dangerous (which means it will require elevated priviledges) because the command won't run, unless you use sudo
. Obviously, running everything using sudo
without truly needing it completely defeats the purpose of having a different user than root. You should always do things without sudo, and only when elevated permissions are needed (aka you get an error without it) you'll consider using sudo
. And before that, you need to make sure you know what your next command will do!