Creating User and Groups
Creating User and Groups
The useradd username command creates a new user named username. It sets up the
user's home directory and account information and creates a private group for the user named
username. At this point, the account does not have a valid password set, and the user cannot log in until a password
is set.
• The userdel username command removes the details of username from /etc/passwd, but
leaves the user's home directory intact.
• The userdel -r username command removes
1. You can use the #id command to check the information about the currently logged-in user.
# id
uid=1000(user01) gid=1000(user01) groups=1000(user01)
context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
To view basic information about another user, pass the username to the id command as an
argument.
# id user02
uid=1002(user02) gid=1001(user02) groups=1001(user02)
context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
2. Adding a user
# useradd username
Add a User with Home Directory, Shell, Custom Comment, and UID/GID
4. Adding a group
The syntax for groupadd command
# groupadd groupname
# groupadd -r mysystemgroup
A better way to change the user's home directory is to use the -m option with -d. This way, it will
create a new home directory if it doesn’t exist. It will also move the content of the old home directory
to the new home directory with correct file permissions and ownership.