Create and delete users on CentOS 7 – Quickly and Securely

In this article from Orcacore, we want to teach you how to create and delete users on Centos 7. Creating and deleting users allows administrators to control access to resources and ensure the security and integrity of their CentOS 7 servers. It is the most basic task that you should know about.

How to create and delete users on CentOS 7

In this guide, we’ll explore how to create and delete users, providing step-by-step instructions for these essential tasks.

Create a user on CentOS 7

You can create a user as a root user any time you want with the following command:

adduser username

Note: If you are a non-root user with accessing root privileges you can use sudo before each command:

sudo adduser username

Now you need to set a password for your new user. You can do it with the following command:

Passwd username

Note: Remember to use sudo privileges if you are a non-root user.

Give sudo privileges to a user on Centos 7

If a user on CentOS 7 wants to use a command with root privileges, the user should have access to sudo privileges.
Sudoers are in a group named “wheel”, they have access to root privileges.
You can add a user in “wheel” to have sudo access with the following command:

gpasswd -a username wheel

If you are a non-root user use sudo privileges:

sudo gpasswd –a username wheel

Now your new user has access to root privileges.

With the lid command, you can see that your user is in which group, and with the –g switch you can see which users are in that group. In your output, you can see usernames and UIDs.

lid username
lid –g wheel

Delete a user on Centos 7

If you don’t want your user anymore you can run the following command:

userdel username

Note: This command will not delete the home directory. If you want to delete the home directory too use the –r switch:

userdel –r username

As we mentioned before remember to use sudo before each command if you are a non-root user to have access to the root privileges.

Conclusion

Managing user accounts is an essential task of maintaining the security of a CentOS 7 server. By following the steps in this guide, administrators can easily create and delete users on Centos 7, ensuring proper access control and system maintenance.

Hope you enjoy this article about How to create and delete users on CentOS 7.

For more articles, you can visit our articles on Linux Tutorials.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!