CentOS user and group, Create user and add it to the sudoers list

Create user and add to the exiting group:

/usr/sbin/useradd -G {group-name} username

if the group does not exist, create it first:

/usr/sbin/groupadd group_name

If you do not use the group option then the user will be assigned to the group with the same name user name.

Remove a user:

sudo /usr/sbin/userdel

usr -r option if you also want to delete the user's home folder

User and group related files:

cat /etc/passwd

cat /etc/group

Example:

Create a user and add the user to the sudoers list: Use root account to do the following steps


1. create sudoers group: /usr/sbin/groupadd sudoers


2. create user: /usr/sbin/useradd -G sudoers htang

3.  modify the /etc/sudoers file bu adding the write attribute

chmod +w /etc/sudoers

4. modify the following lines:

## Allows people in group wheel to run all commands
#%wheel ALL=(ALL)    ALL

to

## Allows people in group wheel to run all commands
%sudoers  ALL=(ALL)    ALL

change the %wheel to %sudoers and remove the comment

5. remove the write attribute of /etc/sudoers file

chmod -w /etc/sudoers

No comments:

Post a Comment

Datatable static image not found on the server

When you use ```datatables.min.css``` and ```datatables.min.js``` locally, instead of datatables CDN, you may have encountered that ```sort...