Skip to main content

 Notes by vishalk17 ( t.me/vishalk17 ) Devops 

 Chapter 3 : Linking/archieve/add-remove-users/disk space/size of file

=====================================================================

groupadd command in Linux with examples

          Groups in Linux refer to the user groups. In Linux, there can be many users of a single system. In a scenario where there are many users, there might be some privileges that some users have and some don’t, and it becomes difficult to manage all the permissions at the individual user level. So using groups, we can group together a number of users, and set privileges and permissions for the entire group. groupadd command is used to create a new user group. 

    We can use either usermod or gpasswd command to add user to group in Linux operating system. And both commands are very easy to use.

 

Syntax

groupadd [option] group_name        

 

Every new group created is registered in the file “/etc/group“. To verify that the group has been created, enter the command

tail /etc/group

 


The file shows group information in the following format:

group_name : password : group-id : list-of-members

 

 

 

 

To add an existing user to a group, use the usermod command :

 the group is mentioned using -g option in the command useradd

usermod -G groupname existing_user

 


The file shows group information in the following format:

group_name : password : group-id : list-of-members-in

 

Every new group created is registered in the file “/etc/group“. To verify that the group has been created, enter the command :

sudo tail /etc/group

 

example case :   I want to give group “developer” root access through which members who are in same group will have root privilege automatically. So what I m going to is ,

visudo or use any text edior to edit /etc/sudoers

 


Image shows developer group added. And given permission of root

Save /etc/sudoers file and exit.

 

Now, members of group developer will have root privilege.

Testing:


 

 

How to delete group :


 

 

 

 

 

 

 

 

 

 

 

 

How to Manage Groups using “gpasswd” Command

 

The gpasswd command is used to administer /etc/group, and /etc/gshadow. Every group can have administrators, members and a password  in linux to remove user from group, add users to group, list group members and set password for a group.

    We can use either usermod or gpasswd command to add user to group in Linux operating system. And both commands are very easy to use.

 Syntax

gpasswd [options] group

 

-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.

Add a User to a group using gpasswd comand

Let check how to add a 'existing_user' to a group  'group_name'

$ gpasswd -a existing_user group_name


Add multiple user to a group

To add multiple users to sales group following below command:

To add multiple users to “group_name” group following below command:

$ gpasswd -M user1,user2,user3 group_name

 



 

 

 

 

 

 

 

Remove a user from group

We can use -d option to remove a user from a group.

Following command will remove user 'prashant' from the  'aws_development' group.

$ gpasswd -d user group_name

 

 


 

 

 

 

 

 

 

 

Linux permissions: chown, chgrp and chmod

 

In Linux EVERYTHING is a file: folders, files themselves, programs, even hard disks! Knowing that, every file has permissions.

 

Read, Write and Execute

Read, Write and Execute are the three basic permissions, you won’t need anything else to get started, but before we get ahead and understand how to use them, it’s important to understand what they do.

§  Read: will enable you to read the file (or the folder’s table of contents), as the name suggest.

§  Write: with this you can modify the file (or create a new file in the case of a folder).

§  Execute: enables you to run the program; if it is set on a folder enables you to access that folder.

 

Read, Write and Execute have different forms

We read them as words, but for computers it’s not that simple, to tell the truth… read, write and execute are actually… numbers! (bits to be more precise). Since the entire word “read” or “execute” is way too big to be listed and repeated many times, you won’t usually find permissions in the form of read/write/execute, instead you will find one of these two forms:

§  Read: either r or 4

§  Write: either w or 2

§  Execute: either x or 1

 

User, Group and Others

 

Each file will have these three subjects. Each subject will have its own permissions.

The user subject is the owner of the file, he usually has the highest level of permissions.

The group subject is the group assigned to that file, meaning that if the group has writing permission (w) each user of that group will have writing permissions (so long they are still in that group).

The other subject is simply ANYONE else. Be careful when assigning permissions to these three subjects, since they are the most basic and most permissive form of control.

*************************************************************************************

Before we dive into the world of permissions you must learn how to check them in the terminal. This can be achieved using the ls command.

ls -l

Ls is a basic Linux command which lists the files in your current folder, using the -l flag you can learn what permissions are associated with the files. Let’s give it a look!


Okay, now let’s try to understand. Here’s how ls shows its output:

file (-) /directory(d) / soft linked(l), permissions, number of links, user, group, size, date, time, name

 

     let’s focus only on permissions, user and group. In this case the

user is ec2-user and the group is ec2-user. The permission column is a little bit more difficult, but fear not and let’s analyze it:

 

-rw-rw-r—
file (-) /directory(d) / soft linked(l), permissions,

The first bit isn’t important for this lesson, let’s look at the remaining 9.

The first three are the user‘s permissions,

the second three are group‘s permissions

the remaining three are others permissions

 

chown

It is used to change the owner (or user subject). Its syntax is:

 

chown owner filename


chgrp

Chown changes file’s user, while chgrp changes file’s group. Its syntax is:

 

chgrp group_name filename


chmod

It is used to change the permissions of the three subjects and its syntax is:

 

$ chmod permission filename/foldername

Now the problem is what goes into the permission field?

 

 I mentioned you can use two forms to represent permissions: r w x or 4 2 1, in this case we’ll be using the numerical form.

 

Example,

 

let’s suppose we want to assign :

 

read+write+execute to owner,

read to group and

none to others.

 

§  Read: either r or 4

§  Write: either w or 2

§  Execute: either x or 1

 

It’s time to calculate:

§  owner will be read+write+execute=4+2+1=7

§  group will be read=4

§  others will be = 0

 

So, number is 740! Let’s use it on Android.mk

 


Notice how it changed. Now suppose we want to full permissions to everyone! Can you guess which number I will use?


If you said 777, then you’ve answered correctly!

 


Comments

Popular posts from this blog

Chapter 1 : Basics of Vi editor

 Notes by vishalk17 ( t.me/vishalk17 ) Devops  =====================================================================   1.    Starting vi Open a file with vi. Type:  vi myfile.txt 2.    vi Modes Command Mode o    Command mode is the mode you are in when you start (default mode) o    Command mode is the mode in which commands are given to move around in the file, to make changes, and to leave the file o    Commands are case sensitive: j not the same as J Insert (or Text) Mode o    The mode in which text is created. o    There is more than one way to get into insert mode but only one way to leave: return to command mode by pressing  <Esc> 3.    Setting Basic Options in vi Displaying Line Numbers     From Command Mode        :set nu     Display line numbers        :set nonu   Hide line numbers       4.    Basic commands To repeat and undo: Commands Action u Undo the last command . Repeat the l

Chapter 2 : Linking/archieve/add-remove-users/disk space/size of file

Notes by vishalk17 ( t.me/vishalk17 ) Devops    Chapter 2 : Linking/archieve/add-remove-users/disk space/size of file ===================================================================== Linking:   Soft Links vs Hard Links The  ln  command can be used to create two different kinds of links: Soft links (for files / directories) Hard links (only for files) Soft (Symbolic) Links (for files /directories) A soft link, sometimes called a symbolic link or  symlink , points to the location or  path  of the original file. It works like a hyperlink on the internet. Here are a few important aspects of a soft link: If the original file is moved or deleted, the symbolic link won’t work. A soft link can refer to a file on a different file system. Soft links are often used to quickly access a frequently-used file without typing the whole location. A soft link is something like a shortcut in Windows. How to Use the ln Command  By default, the ln command cre