Add/Remove User, Give it Root Privilege and Disable Root Account on Debian 10 Server



Hello Friends,
A lot of people are switching to debian server after what happened with centos, me included and today we will try to learn how to manage users on debian 10. I'll share a lot of posts in the future about debian, I'll share what I'll learn, Let's get straight to the point

  •  Adding/Removing Users

To add a new user -Let's say the user is codivya- to the system you simply need to type this command and follow the instructions

$ sudo adduser <username>
example: $ sudo adduser codivya

You will be asked to enter the user password, just type a new password then repeat the password, then you will be asked to enter some information to that new user, you are free to leave it all blank.

To remove a user from the system you will simply need to type the following command

$ sudo deluser <username>
example: $ sudo deluser codivya

be aware that command just delete the user from the system without deleting its files in the home directory, if you want to delete the user with its home directory just type

$ sudo deluser --remove-home <username>
example: $ sudo deluser --remove-home codivya

  • Give a user root privilege

There is more than one method to give a user a root privilege, but first you need to access root by just typing

$ su

then type your password. The first method is by typing

# usermod -aG sudo <username>
example: # usermod -aG sudo codivya

if that doesn't work, try to add /sbin/ before usermod

# /sbin/usermod -aG sudo <username>
example: # /sbin/usermod -aG sudo codivya

the second method is by using gpasswd to give a user root privilege

# gpasswd -a <username> sudo
example: # gpasswd -a codivya sudo

that shall do, just test that the user has the privilege now, just type

# exit

then you need to make a test, let's say apt update, type

$ sudo apt update

if you got the update successfully that's mean we successfully give that user a root privilege.

  • Enable/Disable root account

To disable the root account after we give our new user the root privilege is to type

$ sudo passwd -l root

to be honest I recommend to disable it for security purposes

To Enable the root account again just type

$ sudo passwd root

You will be asked to enter a new password and then repeat the password, that's how to enable the root account again.


Thanks my friend for your time of reading this quick post, I hope you find it useful and it adds value to you.

Comments