Understanding and Basic Management of User and Group File Permissions in Ubuntu

By Łukasz Kallas
Picture of the author
Published on
aws image

File Permissions Overview

In Linux, every file and directory has a set of permissions associated with three types of users:

  • Owner: The user who owns the file.
  • Group: A set of users who share access.
  • Others: Everyone else.

Understanding Permission Types

Each permission is represented by a character in a sequence:

  • r (read): Permission to read the file or list directory contents.
  • w (write): Permission to modify the file or directory contents.
  • x (execute): Permission to run the file as a program or to access a directory.

Reading Permissions

You can view the permissions of a file or directory using the ls -l command:

ls -l filename

This command will output something like:

-rwxr-xr--

This string represents the permissions:

  • The first character (-) indicates the type of file (e.g., - for a file, d for a directory).
  • The next three characters (rwx) are the owner's permissions.
  • The next three (r-x) are the group's permissions.
  • The last three (r--) are the others' permissions.

Setting Permissions

You can change file and directory permissions using the chmod command.

Using Symbolic Mode

You can adjust permissions by adding or removing permissions:

chmod u+x filename  # Adds execute permission for the user
chmod g-w filename  # Removes write permission for the group
chmod o+r filename  # Adds read permission for others
Using Numeric Mode

Permissions can also be set using a numeric mode, where:

4 = read (r) 2 = write (w) 1 = execute (x)

For example, to set read, write, and execute permissions for the owner and read and execute for others:

chmod 755 filename

This sets:

7 for the owner (rwx) 5 for the group (r-x) 5 for others (r-x)

Changing Ownership and Groups

Changing the Owner

To change the owner of a file or directory, use the chown command:

sudo chown newowner filename
Changing the Group

To change the group associated with a file or directory, use:

sudo chown :newgroup filename

Or you can change both the owner and group simultaneously:

sudo chown newowner:newgroup filename

Stay Tuned

Want to learn?
The best articles, links and news related to software development delivered once a week to your inbox.