Page 84 - DCAP602_NETWORK_OPERATING_SYSTEMS_I
P. 84
Network Operating Systems-I
notes
Did u know? What will happen if user account is used without specifying a username?
add a user to a group
Usermod is used to modify a user account’s settings. Check the manpage for all the available
options. One useful use of this command is to add a user to a group:
# usermod -a -G group1 username
The -a option is critical. The user is added to group1 while he continues to be a member of other
groups. If it’s not used, then the user is added only to group1 and removed from any other
groups. So, take note.
remove a user from a group
Removing a user from a group is a bit trickier. Unfortunately, there is no direct command, at
least not in Fedora or RHEL, that can do that from command line. At first you need to get a list of
groups that your user is a member of:
# id -nG username
group1 group2 group3 ....
Then you need to put all these groups as a comma-separated list to the usermod -G option, except
for the group from which you want the user to be removed. So, to remove the user from group2,
issue the command:
# usermod -G group1,group3,... username
Lock and unlock user accounts
Other common usermod uses are to lock and unlock user accounts. To lock out a user:
# usermod -L username
To unlock the user:
# usermod -U username
Delete a user
Userdel is used to delete a user account. If the -r option is used then the user’s home directory
and mail spool are deleted too:
# userdel -r username
create a new group
To create a new group, issue the command:
# groupadd groupname
The -r option can be used to create a group with GID<500 (system).
Change a Group’s Name
Groupmod can be used to change a group name:
# groupmod -n newgroupname groupname
78 LoveLy professionaL university