Saturday, March 19, 2011

Managing users and groups

To add a new user:
# useradd -m user_name

To set or change a user password :
# passwd user_name

To modify an user account:
# usermod [options] user_name

To delete an user:
# userdel - Delete a user account and related files
# deluser - remove a user from the system

To add an user to a secondary group (append a group to a user):
# usermod -aG group_name user_name

To show the groups that belongs a user:
This show a reduced set of groups (maybe just the secondary groups)
# groups user_name

If the user uses the command groups without a user name, it will show an extended list of groups (maybe the primaries and secondaries groups)

The command id -nG user_name has the same behavior that group.

To remove a user from a group:
it is needed write all the groups the user belongs less the unwanted groups.
# usermod -G {groupname1,groupname2,...} user_name

To add a new group:
 # groupadd group_name

To modify a group:
 # groupmod [options] group_mane

To delete a group:
# groupdel - Delete a group
# delgroup - remove a group from the system

You can edit manually the OS groups file (needs logout-login):
# vi /etc/group

Example:
In KDE with HAL: The error that appears when I pugged a USB HDD was solved adding my user to the groups users and plugdev:
# usermod -aG users my_user
# usermod -aG plugdev my_user

No comments: