Wednesday, February 18, 2015

how to create group in linux ?



about groups

Users can be listed in groups. Groups allow you to set permissions on the group level instead of having to set permissions for every individual user. Every Unix or Linux distribution will have a graphical tool to manage groups. Novice users are advised to use this graphical tool. More experienced users can use command line tools to manage users, but be careful: Some distributions do not allow the mixed use of GUI and CLI tools to manage groups Senior administrators can edit the relevant files directly with vi or vim.

groupadd

Groups can be created with the groupadd command. The example below shows the
creation of five (empty) groups.

root@linuxforfreshers:~# groupadd tennis
root@linuxforfreshers:~# groupadd football
root@linuxforfreshers:~# groupadd snooker
root@linuxforfreshers:~# groupadd formula1
root@linuxforfreshers:~# groupadd salsa


/etc/group

Users can be a member of several groups. Group membership is defined by the /etc/
group file.

root@linuxforfreshers:~# tail -5 /etc/group
tennis:x:1006:
football:x:1007:
snooker:x:1008:
formula1:x:1009:
salsa:x:1010:
root@linuxforfreshers:~#

The first field is the group's name. The second field is the group's (encrypted)
password (can be empty). The third field is the group identification or GID. The
fourth field is the list of members, these groups have no members.

usermod

Group membership can be modified with the useradd or usermod command.
root@linuxforfreshers:~# usermod -a -G tennis inge
root@linuxforfreshers:~# usermod -a -G tennis katrien
root@linuxforfreshers:~# usermod -a -G salsa katrien
root@linuxforfreshers:~# usermod -a -G snooker sandra
root@linuxforfreshers:~# usermod -a -G formula1 annelies
root@linuxforfreshers:~# tail -5 /etc/group
tennis:x:1006:inge,katrien
football:x:1007:
snooker:x:1008:sandra
formula1:x:1009:annelies
salsa:x:1010:katrien
root@linuxforfreshers:~#

Be careful when using usermod to add users to groups. By default, the usermod
command will remove the user from every group of which he is a member if the group
is not listed in the command! Using the -a (append) switch prevents this behaviour.


groupmod

You can change the group name with the groupmod command.

root@linuxforfreshers:~# groupmod -n darts snooker
root@linuxforfreshers:~# tail -5 /etc/group
tennis:x:1006:inge,katrien
football:x:1007:
formula1:x:1009:annelies
salsa:x:1010:katrien
darts:x:1008:Sandra


groupdel

You can permanently remove a group with the groupdel command.

root@linuxforfreshers:~# groupdel tennis
root@linuxforfreshers:~#


groups

A user can type the groups command to see a list of groups where the user belongs to.

[root@linuxforfreshers ~]$ groups
harry sports
[root@linuxforfreshers ~]$

No comments:

Post a Comment