Wednesday, May 7, 2014

User and Group Administration in Linux

User and Group management is essential skill of the System Administrator.

To add a new user

# useradd newuser
-c - "Comment" - you can comment user's name or anything
-G - Group user belongs to (by default user group will be same as its username)
-e - expiration date of the user's account
-d - custom home directory
-p - set a password
-s - custom shell for a user

You can modify user's account

#usermod user1

Above options will work with usermod and plus some extra commands
-L - lock user's account
-U - unlock user's account
-m - move home dir to another location

You can delete user with

#userdel username
#userdel -r username -> deletes users fully (recursively) from the system

You can modify user's account password with

#passwd user1 - change password for a user
#passwd -l username > to lock user's account
#passwd -u username > to unlock user's account
#chage - changes user password age
#chage -E year-month-date > sets an expiration date
#chage -W 2 > sets a warning for a password expiration
#chage -M 30 > sets a maximum (30) days for the user's account to expire
#chage -l $username > lists information about the user's account

You can create a groups in Linux

#groupadd Groupname - > Adds a group
#groupmod Groupname -> Modifies a group
#groupdel Groupname - > Deletes a group

#groupmod -n oldname newname
#groupmod -g 1001 groupname -> changes group's id

You can set up particular user as an Admin of the group
#gpasswd -A username groupname

Now user can add users to the group he or she is admin of
#gpasswd -a username groupname

User configuration file: /etc/passwd
User password configuration file: /etc/shadow

Group configuration file: /etc/group
Group password file: /etc/gshadow

If you want, you can use GUI too under SYSTEM > ADMINISTRATION > USERS&GROUPS.

No comments:

Post a Comment