>_ IzzyLab

Hands-on task

This task is step 16 of the course “First steps in Linux”

Set permissions on a file

easy~6 min

/srv/app/secret.env holds the database password. Right now the file belongs to root, and any user on the server can read it — that won't do.

  1. Make the user deploy the file's owner and the group deploy its group.
  2. Set the permissions so that the owner can read and write, the group can only read, and everyone else gets nothing.
What you'll practise:
  • chmod
  • chown
  • file permissions
  • owner and group
  • octal permissions

Topic breakdown

Every file has an owner and a group, and its permissions are written as three triplets: for the owner, for the group and for everyone else. A triplet has three letters: r — read, w — write, x — execute; a dash means "not allowed". You can see them in ls -l:

-rwxr-xr-x 1 root root 120 May 14 10:00 tool.sh

Here the owner can do anything, while the group and everyone else can read and run it.

chown user:group file changes the owner and the group. chmod sets the permissions, most conveniently as a number: each triplet gets a digit made up of r = 4, w = 2, x = 1. tool.sh above has 755: 4+2+1, 4+1, 4+1.

What's checked

  1. The file's owner and group are deploy
  2. The file's permissions match the task
  3. The file's contents are untouched

What it looks like