Information Technology Tips

Innotechtips_logo_v4
Menu
  • Home
  • Linux
  • Programming
  • Other Tech Tips
    • Windows
    • Security
Youtube
Home Linux

File/Directory Ownership and Permissions in Linux

Inno by Inno
July 27, 2023
File/Directory Ownership and Permissions in Linux

Linux is a multi-user operating system which means that a system can be accessed by multiple users simultaneously. To protect against unauthorized file and directory modification, Linux provides security through ownership and permissions. Every file and directory in Linux is associated with three types of owners: user, group, and other. The user or the person that created the file is often the owner of the file. A group consists of users who share the same permissions as it relates to a given file or directory. Associating permissions to a group is much more convenient than assigning permissions separately to every individual belonging to the group. Finally, the other owners (also referred to as the world) include anyone else that that accesses the file/directory.

File/Directory Permissions

File permissions in Linux are broken down into three categories: read, write, and execute. The read permissions provide the authority to open and read a file. When it comes to a directory, read permissions allow one to list its contents. The write permissions provide authority that allows modification of a file. Write permissions on directories allow for the addition, renaming, and removal of files inside a directory. The execute permissions allow one to run a given file or program. In Linux, a program cannot be run if the execute permission is not set.

To see what files and directories are contained in the current directory we will use the command ‘ls -l’. At the left side and beginning of the row, we have the permissions for the file or directory. The first letter describes whether it is a file (represented by a -) or a dictionary (represented by the letter d). This is followed by three sets of permissions in the form of ‘-rw-rw-rw-’.

In the below screenshot, the top row starts with a ‘–’ which represents a file named file3 while the second row starts with ‘d’ which represents a directory named Music. After the ‘-‘ we have ‘rw-rw-rw-’. Here, the first three characters ‘rw-’ represent the permissions for the user or owner of the file which also happens to be called ‘user’. The second set of three characters ‘rw-’ represent permissions for the group which in this case is called ‘user’. The last three characters ‘r–‘ are the permissions for the others or world.

The character ‘r’ represents read permissions, ‘w’ represents write permissions, and ‘x’ represents execute permissions. The characters ‘rw-’ means that one has read and write but no execute permissions. The characters ‘r–‘ means that one has only read permissions.

Changing File Permissions

Linux provides the command ‘chmod’ (short for change mode) for the purpose of modifying read, write, and execute permissions. There are two modes under which permissions can be changed: absolute and symbolic. The absolute mode allows permissions to be specified in the form of a three-digit octal number. The digits range from 0 to 7 where 0 provides no permissions while 7 gives read, write, and execute permissions. The table below shows the digit, permission type, and symbol type.

The screenshot below shows an example of the use of the command ‘chmod’. Here the command is used to change the permissions for the user from  â€˜rw-’ to ‘rwx’ and that of the group from ‘rw-’ to ‘r-x’ by using the command ‘chmod 754 file3’. The absolute mode is represented by ‘754’ which gives the file owner read, write, and execute permissions. The group is given write and execute permissions while the others are given just read permissions.

The symbolic mode is another option for modifying file permissions. The symbolic mode syntax does not involve octal digits like the absolute mode. The symbolic mode makes use of the ‘+’sign for adding permissions, the ‘-’ sign for removing permissions, and the ‘=’ sign for setting permissions. The three different owners are represented by the character ‘u’ for the user, ‘g’ for the group, ‘o’ for other, and ‘a’ for all.

In the below screenshot, the permissions for the group have been changed from ‘r-x’ to ‘rwx’ using the command ‘chmod g=rwx file3’. On the other hand, the permissions for others have been modified from ‘r–’ to ‘rw-’ using the command ‘chmod o+w file3’.  

Changing File Ownership and Group in Linux

Linux provides the capability to modify the owner of a file and also the group associated with the file. File ownership can be changed using the command ‘chown’ (short for change owner). For instance, in Ubuntu, if we wanted to change the ownership of the file named file3 from user to root, we can leverage the command ‘sudo chown root file3’ as shown below.

When it comes to changing a group, the command ‘chgrp’ (short for change group) can be used. For example, in order to change the group from user to root, we will use the command ‘sudo chgrp root file3’

Inno

Inno

Related Posts

Linux

Getting Started with Kali Linux: A Guide for Beginners

July 31, 2024
Linux

20 Linux Commands for Beginners

March 31, 2024
Linux

What is KVM Virtualization?

March 31, 2024
Linux

The Linux Booting Process in Linux

February 17, 2024

Category

  • Linux
  • Other Tech Tips
  • Programming
  • Windows

Recommended.

What is KVM Virtualization?

March 31, 2024
How to Connect to Kali Linux from Window’s Command Prompt

How to Connect to Kali Linux from Window’s Command Prompt

July 27, 2023

Trending.

How to Install and Enable Free VPN in Kali Linux

July 27, 2023

How To Connect Kali Linux to Wi-Fi on VirtualBox

October 9, 2023

How to Connect Kali Linux on VMware Workstation to a Wi-Fi Network

July 27, 2023

How to Capture Network Traffic on a Wi-Fi Network using Kali Linux

July 27, 2023

IPv4 to IPv6 Transition Challenges

July 27, 2023

About us

This site is dedicated towards highlighting various important aspects of information technology. The key areas includes programming, Linux, software, and security. The content will include articles as well as videos.

Quick Links

Menu
  • Home
  • Linux
  • Programming
  • Other Tech Tips
    • Windows
    • Security

Privacy Policy

Menu
  • Privacy Policy
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}
No Result
View All Result
  • Cookie Policy (EU)
  • Home 1
  • Home 2
  • Home 3
  • Mytest Page
  • Privacy Policy

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.