Performing server administration as a non-root user is a best practice for security. After launching your OneHost Cloud VPS, your first task as root should be to set up a non-root user with sudo access.
This guide applies to the following versions:
Most Debian installations do not come with sudo installed. Install sudo using apt.
# apt install sudo
Create a new user account with the adduser command. Use a strong password for the new user. You can enter values for the user information, or press ENTER to leave those fields blank.
# adduser example_user
Adding user `example_user' ...
Adding new group `example_user' (1001) ...
Adding new user `example_user' (1001) with group `example_user' ...
Creating home directory `/home/example_user' ...
Copying files from `/etc/skel' ...
Retype new password:
passwd: password updated successfully
Changing the user information for example_user
Enter the new value, or press ENTER for the default
Full Name : Example User
Room Number :
Work Phone :
Home Phone :
Is the information correct? [Y/n] y
Add the new user to the sudo group with usermod.
# usermod -aG sudo example_user
Switch to the new user.
# su - example_user
Verify you are the new user with whoami, then test sudo access with sudo whoami, which should return root.
$ sudo whoami
[sudo] password for example_user:
The new user account is ready to use. As a best practice, use this sudo user for server administration. You should avoid using root for maintenance tasks.
Powered by BetterDocs