Having only one user, which is root, can be dangerous. Running your own personal server allows you the freedom of doing whatever you wish, so let’s make use of this by adding a user with sudo access instead of direct root access.
We need to first connect to the server with root so that we have adequate permissions. Once connected, add another user account.
# useradd <username>
Replace <username>
with the desired username.
That command will add the user to the list of users on the system, and create a corresponding group (if the group doesn’t exist).
Now we need to give this new user sudo access. We do this by editing the “sudoers” file.
Even if you’re root, you will need to run the “sudo” part of the following command.
sudo visudo
This will bring up a file with a bit of default info. What you need to look for is the following section:
# Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL
Find where “root” appears in the list shown above, and add the following below it.
Substitute the appropriate variables.
<username> ALL=(ALL:ALL) ALL
We are almost finished. A few more minor steps.
Create the home folder for the new user.
mkdir /home/<username>
Give the new user permissions in that folder.
chown <username>:<usergroup> /home/<username> -R
Set a password for the new user.
sudo passwd <username>
Add the following to the /etc/passwd
file.
<username>:x:1000:1000::/home/<username>:/bin/bash
Reboot the server for these changes to take effect.
reboot
Your new user account is now ready-to-go with sudo access! You may log into the server with this new account and use sudo
when necessary.