Back to Lab Listing

Lab Objective:

Learn how to manipulate file permissions and ownership settings.

Lab Purpose:

In this lab, you will learn to use chmod and chown, as well as view permissions and ownership settings with ls.

Lab Tool:

Ubuntu 18.04 (or another distro of your choice).

Lab Topology:

A single Linux machine, or virtual machine

Lab Walkthrough:

Task 1:

Open the Terminal and run:

  • echo “Hello World” > foo
  • ls -l foo

Look at the first field; you should see -rw-r–r–

This indicates the user, group, and other permissions. The last nine characters, in groups of three, denote these permissions. In this instance:

rw- indicates read/write (but not execute) permissions for the user who owns the file

r– indicates read-only permissions for the group that owns the file

r– indicates read-only permissions for all non-owners, a.k.a. “world”

The first character indicates the type of file. In this case it is a regular file; directories begin with d.

Who are the user and group owners of this file? The third and fourth fields of ls -l tell us that. By default, it should be your own user and primary group.

Task 2:

Now run:

  • sudo chown root foo
  • ls -l foo
  • cat foo

You’ve just changed the user ownership to root, while keeping the group ownership. As the file has group- and world-read permissions, you can still see its contents.

Task 3:

Now run:

  • sudo chmod o-r foo
  • ls -l foo
  • cat foo

That chmod command removes read permissions from other. However, as you still have group ownership, you can still see the file’s contents.

Task 4:

Now run:

  • sudo chmod 600 foo
  • ls -l foo
  • cat foo

This chmod command explicitly sets permissions to read-write for the owning user only. As that is the root, we can no longer read the file.

Task 5:

Finally, clean up with sudo rm foo

Notes:

Execute permissions apply to executable files as well as directories. If a user/group cannot “execute” a directory, it cannot view the contents of said directory or any subdirectories.

Newsletter Subscribe

Stay Informed, Stay Inspired: Subscribe for Cutting-Edge IT-Certification Insights

101 Labs Newsletter