- So now that you know how to work with users,
you should also know how to work with groups.
So in order to create groups, you use groupadd
followed by the name of the group
and then you can add users to a group
as a secondary group using usermod -aG groupname username.
Let me just show you.
Now, the first that we should explore
is a statement as a secondary group.
What is the thing if I use id on bill
to explore the properties of user bill,
then we can see that while I created user bill,
useradd has also created a group with the name bill.
We can even verify
if I use grep bill on etc group.
Etc group is where the groups are stored.
You can see that group bill is created.
So if it's for the primary group
you don't have to do anything.
If it's for the secondary group
you do need to do something.
So sudo groupadd sales, for instance
is creating a group with the name sales.
We can verify that.
Grep sales in etc group and yay,
the group has been created,
but now I want users to be a member.
Then I need usermod.
So sudo usermod -aG sales bill
is doing what?
This is adding user bill as a member to the group sales.
Now this does not change anything about the ownership.
Let me show you sudo su - bill.
I have no password for bill.
So this is the only way that I can easily get
into a shell is user bill.
And let me create a file with the name bilfile
and ls -l and there we can see ownership is still set
to bill and bill.
Secondary groups are cool,
but secondary groups are mainly to grant permissions
to additional items.
They are not used for ownership by default.