Bog'liq Mastering Ubuntu Server Gain expertise in the art of deploying, configuring, managing, and troubleshooting Ubuntu Server by Jay LaCroix (z-lib.org)
[ 57 ] The way this works in Linux is that every file or directory has both a user and a group
that takes ownership of it. This is contrary to platforms such as Windows, which can
have multiple groups assigned to a single resource. With Linux, it's just one-to-one
ownership: just one user and just one group assigned to each file or directory. If you
list the contents of a directory on a Linux system, you can see this for yourself:
ls -l
The following is a sample line of output from a directory on one of my servers:
-rw-r--r-- 1 root bind 490 2020-04-15 22:05 named.conf
In this case, we can see that
root
owns the file and that the group
bind
is also
assigned to it. Ignore the other fields for now; I'll explain them later when we get to
the section of this chapter dedicated to permissions. For now, just keep in mind that
one user and one group are assigned to each file or directory.
While each file or directory can only have one group assignment, any user account
can be a member of any number of groups. Entering the
groups
command by itself
with no options will tell you what groups your logged-in user is currently a member
of. If you add a username to the
groups
command, you'll see which groups that user
is a member of. Go ahead and give the
groups
command a try with and without
providing a username to get the idea.
On the Ubuntu Server platform, you'll likely see that each of your user accounts is a
member of a group that's named the same as your username. As I mentioned earlier,
when you create a user account, you're also creating a group with the same name as
the user. On some Linux distributions, though, a user's primary group will default to
a group called
users
instead. If you were to execute the
groups
command as a user
on the Ubuntu desktop platform, you would likely see additional groups. This is due
to the fact that distributions of Linux that cater to being a server platform are often
more stripped down and users on desktop platforms need access to more things such
as printers, audio cards, and so on. Some packages that can be installed also add
additional system users to the server.
If you were curious as to which groups exist on your server, all you would need
to do is
cat
the contents of the
/etc/group
file. Similar to the
/etc/passwd
file we
covered earlier, the
/etc/group
file contains information regarding the groups that
have been created on your system. Go
ahead and take a look at this file on your
system:
cat /etc/group