http://www.debianadmin.com/users-and-groups-administration-in-linux.html
Add New User in Linux
-d home directory
-s starting program (shell)
-p password
-g (primary group assigned to the users)
-G (Other groups the user belongs to)
-m (Create the user's home directory )
useradd -g test1 -G test2 -s /bin/bash -p xxxx -d/home/admin -m admin
This will create a new user admin.
One additional switch worth mentioning is "-D", which controls the defaults for useradd.
Specifying the "-D" switch on its own will simply display the default settings, while specifying -D in conjunction with other switches will change the defaults to those values.
adduser -- User Friendly Frontend for useradd command
adduser [options] user group
#adduser admin
Adding user `admin' ...
Adding new group `admin' (1001) ...
Adding new user `admin' (1001) with group `admin' ...
Creating home directory `/home/admin' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for admin
Enter the new value, or press ENTER for the default
Full Name []: Admin
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [y/N] y
You'll notice that, by default, the adduser command creates a group with the same name as the username, and makes this group the primary group for that user. This is called a user private group (UPG)
Modify User in Linux
usermod -- Modify a user account
Syntax
usermod [-c comment] [-d home_dir [-m]] [-e expire_date] [-f inactive_days]
[-g initial_group] [-G group [,...]] [-l login_name] [-p passwd] [-s shell] [-u uid [-o]] [-L|-U] login
Options:
-d home directory
-s starting program (shell)
-p password
-g (primary group assigned to the users)
-G (Other groups the user belongs to)
To add the group ‘others' to the user admin
#usermod -G others admin
Remove user from group and add another group instead
groups pvcs
pvcs : pvcs wheel
remove group wheel and add oinstall
usermod -g pvcs -G oinstall pvcs
groups pvcs
pvcs : pvcs oinstall
Delete User in Linux
userdel -- Delete a user account and related files
Syntax
userdel [-r] login
If you want to know available options check userdel man page
Options
-r (remove home directory)
To remove the user ‘admin' and his home directory
#userdel -r admin
deluser -- remove a user from the system
deluser [options] user group
If you want more options check deluser man page
Example
By default, deluser will remove the user without removing the home directory, the mail spool or any other files on the system owned by the user. Removing the home directory and mail spool can be achieved using the --remove-home option. If the --home option is given, deluser will only remove the user if the directory given to the --home option matches the user's real home directory.
#deluser --remove-home admin
Groups Administration in Linux
Add New Group in Linux
groupadd -- Create a new group
Syntax
groupadd [-g gid [-o]] group
For more options check groupadd man page
#groupadd test1
This will create a test1 group
addgroup -- add a group to the system
Syntax
addgroup [options] [--gid ID] group
#addgroup
Enter a groupname to add: admin1
Adding group `admin1' (1001)...
Done.
Modify Group in Linux
groupmod -- Modify a group
groupmod [-g gid [-o]] [-n group_name ] group
#groupmod test1 test2
This will modify group name test1 to test2
Delete group in Linux
groupdel -- Delete a group
groupdel groupname
#groupdel test2
this will delete the test2 group
delgroup -- remove a group from the system
Syntax
delgroup [options] [--only-if-empty] group
#delgroup --only-if-empty test2
Removing group `test2'...
done.
groups Command
print the groups a user is in
groups [username]
This simple command displays what groups a user is a member of. It takes the username of user as a parameter. If no username is given, it defaults to the current user.
# groups
root
#groups admin
test1 : test2
File Purpose
/etc/shadow Secure user account information
/etc/passwd User account information
/etc/gshadow Contains the shadowed information for group accounts
/etc/group Defines the groups to which users belong
/etc/sudoers List of who can run what by sudo
/home/* Home directories
List all:
All users:
$ getent passwd
All groups:
$ getent group
All groups with a specific user:
$ getent group | grep username
http://linoxide.com/how-tos/linux-groups-gpasswd/
Manage Linux Group Using gpasswd Command
The gpasswd command (As defined in the man page) is used to administer /etc/group, and /etc/gshadow. Every group can have administrators, members and a password.
Command Options
-a, --add user Add the user to the named group.
-d, --delete user Remove the user from the named group.
-A, --administrators user,... Set the list of administrative users.
-M, --members user,... Set the list of group members.
gpasswd examples
Let us assume that we have a group named sales and three users user1,user2,user3.
Add User
To add user1 to sales group
gpasswd -a user1 sales
Add multiple user
To add multiple users to sales group
gpasswd -M user1,user2,user3 sales
Remove user
To remove user2 from sales group
gpasswd -d user2 sales
How to set a user as group administrator
gpasswd -A user group
or
gpasswd -A user1,user2 sales
Example :
gpasswd -A nixsavy linuxgroup
Set password for group
$ gpasswd linuxgroup
Changing the password for group linuxgroup
New Password:
Re-enter new password:
No Comments