Linux User Group permissions
Welcome to our tutorial Linux group permissions . we have already discussed user permissions in tutorial introduction to linux user permissions. In this tutorial we will use basic commands like
In linux if need to assign permissions to group of specific users to directory you have option to create a group in linux. Put all these users into this group
and then assign permission to that directory at group level instead of individual user. It will be more clear when we use practicle examples.
There are two ways to use group permissions in Linux . GUI tools and command sin CLI mode. GUI tools are available in different distribution of linux new users can use

these GUI tools to grasp concept of group and user permission in linux. People who are comfortable and advanced user can use CLI commands.In this tutorial we will use basic commands like groupadd, groupmod, usermod, groupdel,groups and will also briefly talk about /etc/group file

In this tutorial we will discuss commands

groupadd

To add group to system use command groupadd

Syntax : groupadd groupname
example groupadd teamA

Above command will create a group called teamA

see below example commands

[root@shahid ~]# groupadd development
[root@shahid ~]# groupadd testers
[root@shahid ~]# groupadd sales
[root@shahid ~]# groupadd marketing
[root@shahid ~]# groupadd support

We have added five groups
development
testers
sales
marketing
Support

/etc/group

To view group permission you can view file /etc/group

[root@shahid ~]# [root@shahid ~]# cat /etc/group | tail
stapusr:x:156:
stapsys:x:157:
stapdev:x:158:
tcpdump:x:72:
shahid:x:1000:shahid
development:x:1001:
testers:x:1002:
sales:x:1003:
marketing:x:1004:
support:x:1005:
[root@shahid ~]#

user can be a part of more than one group

first field in file is used for group’s name. Second field is for password and can be empty third field is for group identification (GID). Fourth field is for list of

members in group. In our case we just created groups and have not assigned any user yet so there is nothing

usermod

I have quickly created few new users using useradd command

[root@shahid ~]# useradd john
[root@shahid ~]# useradd michael
[root@shahid ~]# useradd alex
[root@shahid ~]# useradd khalid
[root@shahid ~]# useradd david
[root@shahid ~]# useradd rob
[root@shahid ~]# useradd tim

Now I am going to assign them to different groups

[root@shahid ~]# usermod -a -G development john
[root@shahid ~]# usermod -a -G testers michael
[root@shahid ~]# usermod -a -G sales  alex
[root@shahid ~]# usermod -a -G marketing  alex
[root@shahid ~]# usermod -a -G marketing  khalid
[root@shahid ~]# usermod -a -G support rob
[root@shahid ~]# usermod -a -G support tim

Kool we have added users to group. We used switch -a which means append. If you dont use this switch user will be removed from all previously assigned group and will

be added to new group. Switch -G is group to which you are assigning user. As we mentioned we can and have assigned alex to multiple groups sales and marketing

groupmod

You can change name of group by using command groupmod

group
[root@shahid ~]# groupmod -n dev development
[root@shahid ~]# cat /etc/group | tail
marketing:x:1004:alex,khalid
support:x:1005:rob,tim
john:x:1006:
michael:x:1007:
alex:x:1008:
khalid:x:1009:
david:x:1010:
rob:x:1011:
tim:x:1012:
dev:x:1001:john
[root@shahid ~]#

groupdel

To delete group permanently you can use command groupdel

[root@shahid ~]# groupdel dev
[root@shahid ~]# cat /etc/group | tail
sales:x:1003:alex
marketing:x:1004:alex,khalid
support:x:1005:rob,tim
john:x:1006:
michael:x:1007:
alex:x:1008:
khalid:x:1009:
david:x:1010:
rob:x:1011:
tim:x:1012:
[root@shahid ~]#

groups

if user wants to see list of groups to which user belongs can type command groups
I will switch to my user shahid and will see my userid shahid belongs to which group

[root@shahid ~]# su - shahid
Last login: Fri Feb 19 11:46:05 GMT 2016 from 192.168.156.33 on pts/0
[shahid@shahid ~]$ groups
shahid wheel
[shahid@shahid ~]$

I can see my userid belongs to two groups shahid(default group) and wheel

I hope you have enjoyed this tutorial. feel free to comment/suggest and can subscribe free to our newsletter

SUBSCRIBE OUR NEWSLETTER
I agree to have my personal information transfered to MailChimp ( more information )
Join us by subscribing to our newsletter and learn IT subjects for free
We hate spam. Your email address will not be sold or shared with anyone else.