And now we're back again to take a look at how we can manage
our ownership of our file, and that's using the chown,
change owner, and chgrp commands.
So come on then. Let's dive into our Ubuntu system and just
take a look at what we mean by ownership,
both the group and user owner.
So going through, taking a look at one of the files we've already
created, if I do an ls ‑l, a long listing of newfile2, we can see that
it's owned by the vagrant user and the vagrant group. On an Ubuntu
system, as Red Hat also uses, we use private groups where users belong to
a group of their own name so that nobody else is going to pick up
permissions granted through to that group. On SUSE systems, most users
would normally default to belonging to the users group, so we have to be
a little bit more cautious about permissions granted through to the group.
Running through with the id command, you can see that I don't
belong to any additional supplementary groups.
I only belong to the vagrant group, so there's not too
much I can do with file ownership.
I can't change to other users, and I can only change the
group owner to groups that I belong to. So we need to go
through and resolve this problem.
One easy way, remember I can use sudo to gain privileges, is to go through
and make sure that I assign extra groups to the vagrant user. So we can use
sudo and usermod to modify our user account.
We can then append ‑a to the uppercase G to our secondary or complementary
groups. With this then, we can specify that we want to add in the sudo group
to the group membership of the user, vagrant.
There you go.
That's all done. Running the id command doesn't make any difference.
But if I go through and take a look in the back end,
if I use the id and specify the user, I'm now not checking the current session,
I'm looking at the back‑end configuration. So I need to log out and log in again
to pick up those group changes. We can do that. I'm logging in via Vagrant and
SSH because these systems are managed by the Vagrant virtual machine manager, so
it just makes a very simple way to authenticate and get the IP address. Once I'm
back in, we can see now everything looks good, and I belong to both the vagrant
and sudo groups.
Now with that in mind, and remember what I was saying that as an
ordinary user, I can go through and change to the group owner of a
file to a group that I belong to. When we look at newfile2, we can see
that it's owned by the vagrant group.
I changed the group owner with chgrp, changing it through to the sudo group.
I belong to the sudo group, so I can do that.
And now, of course, when we go through and take a look at it,
we can see then now it's listed with the group owner of
sudo. Now that wasn't too difficult,
but I'm not going to be able to change the user owner with the chown
command, so I'm going to have to elevate my privileges.
Obviously, I can only be one user. I can't belong to multiple users.
We can then go through and say change to the owner of the file
to root, chown root newfile2. List it again.
We can see that has worked.
Now, sticking with our elevated privileges and also with the
chown command, with the chown command,
we can run a little bit of a shortcut. We can actually change the user
owner and the group owner. We separate them with a dot.
But if we don't specify a group name,
we assume the group name is the same as the username.
So this has set then the owner to be vagrant and the group owner to be vagrant.
How cool is that?
Now that's the end of our demonstration, taking a look at
the chown command and the chgrp command.
But as always, take the time to practice this yourself.
The more you are practiced with it, the more you're going to know.
But for the moment, we'll going to return to our slides
and take a look at some of our effective permissions and what we need to do which tasks.