How to Create Users and Groups in CentOS 7? Print

  • 14

Linux is a multi-user OS, a system designed to work promptly with many users simultaneously. Therefore, the most basic task you should know how to do is adding and removing users, which you can do by configuring the Linux system.

When creating a new server, you are only given the root account by default; a root account gives you much power and flexibility. Still, it is also unsafe to regularly use an account with so much power.

For instance, root users are more vulnerable to security exploits since any command running under that account can affect the server's entire file system. Therefore, it is better to add unprivileged users to do common tasks.

You should also create additional accounts for other users who need your server access. Each user should have a different account to monitor and manage their activities. While providing an additional account, you can still acquire administrative privileges (when needed) through a mechanism called 'sudo.'

We will cover steps on creating user accounts, assigning 'sudo' privileges, and creating a group on a CentOS 7 server.

Adding a New User

1. Log in to your server as the root user. 

ssh [email protected]_ip_address

2. Use the adduser command to add a new user to your system.

adduser username

Note – Be sure to replace the username with the user that you want to create.

3. Use the passwd command to update the new user's password. 

passwd username

Note: Set and confirm the new user's password at the prompt.
A strong password is highly recommended.

Linux User Password

Creating a Usergroup

1. To create a group, you need to use the groupadd command.

sudo groupadd NAME-OF-THE-NEW-GROUP

Adding a User to Group

1. Use the usermod command to add the user to the wheel group.

usermod -a -G wheel username

Note: On CentOS, by default, the members of the wheel group have sudo privileges. Be sure to change the username with the actual user which you want to add to the wheel group.

Test Sudo Access on a New User Account

1. Use the su command to switch to the new user account.

su - username

As a new user, verify that you can use sudo by prepending ‘sudo’ to the command you want to run with superuser privileges.
For example, you can list the contents of the /root directory, which is usually only accessible to the root user.

sudo ls -la /root

Note: The first time you use sudo in a session, you will be prompted for the user account password; enter the password to proceed.

Linux User Password

2. To add a user to multiple groups, use the command given below – 

usermod -a -G group1,group2,group3 exampleusername


→ Do you want to install the EPEL repo on Centos?
Please refer to Install EPEL for more details.

→ Want to install and configure Dovecot on Centos?
Please refer to Install Dovecot on Centos for more details.

 


Was this answer helpful?

« Back

chat