DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Real-Time Made Easy: An Introduction to SignalR
  • How to Handle Secrets in Kubernetes
  • Develop Hands-Free Weather Alerts To Ensure Safe Backpacking
  • The Ultimate API Development Guide: Strategy, Tools, Best Practices
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. File Permissions in Linux

File Permissions in Linux

Learn more about file permissions in Linux.

Sudeshna Sur user avatar by
Sudeshna Sur
CORE ·
Jul. 26, 19 · Presentation
Like (3)
Save
Tweet
Share
2.76K Views

Join the DZone community and get the full member experience.

Join For Free

What Are File Permissions and Why Do You Need It?

File permissions are a way to protect files or directories from tampering against malicious attack. It is also used to allow a particular user to read, write, or execute a specific file. File systems use permissions to regulate the level of interaction that system processes can have with files and directories.

How to View File Permissions

To view file permission, go to the command line and type ls -l, which will show up the listing of files along with permissions.

To focus on the first column:

drwxrwxr-x

d

rwx

rwx

r-x

The first one is basically the file type. Here, folder1 is a directory which is represented as d.

The permissions that the owner has over the file.

r- read

w-write

x-execute

The permissions that the group has over the file.

r- read

w-write

x-execute

The permissions that all the other users have over the file.

r- read

x-execute

The file cannot be modified by any other user except sudeshna.

-rw-r--r--

-

rw-

r--

r--

The first one is basically the file type. Here, usr01.txt is not a directory but a file.

The permissions that the owner has over the file.

r- read

w-write

The file cannot be executed by any other user except root.

The permissions that the group has over the file.

r- read

The file cannot be modified or executed by any other user belonging to the group root.

The permissions that all the other users have over the file.

r- read

The file cannot be modified or executed by any other user. Others only have read permissions.


How to Set File Permissions Via Command Line?

 chmod is the command that allows changing the permissions of a file or a directory.

• Symbolic method keywords:

chmod WhoWhatWhich file|directory

    • Who is u, g, o, a (for user, group, other, all)

     • What is +, -, = (for add, remove, set exactly)

      • Which is r, w, x (for read, write, execute)

• Numeric method:

chmod ### file|directory

    • Each digit represents an access level: user, group, other.

     • # is sum of r=4, w=2, and x=1.

For the user, rwx is calculated as 4+2+1=7. For the group, r-x is calculated as 4+0+1=5, and for other users, --- is represented with 0. Putting these three together, the numeric representation of those permissions is 750.

How to Change File/Directory User or Group Ownership

 chown (change owner) changes the owner of a file or directory. To grant ownership of the file example.txt to usr01, the following command could be used:

 chown can be used with the -R option to recursively change the ownership of an entire directory tree.

The chown command can also be used to change the group ownership of a file by preceding the group name with a colon (:). For example, the following command will change the group root to sudeshna:

The chown command can also be used to change both the owner and group at the same time by using the syntax  owner:group. For example, to change the ownership of example.txt to root and the group to user, use:

Note: Only root can change the ownership of a file. Group ownership can be set by root or the file's owner. We can also use the chgrp command instead of chown to change group ownership.

Thank you for reading! We will discuss more about file permissions, masking, and ACLs in the next article.

Linux (operating system)

Opinions expressed by DZone contributors are their own.

Trending

  • Real-Time Made Easy: An Introduction to SignalR
  • How to Handle Secrets in Kubernetes
  • Develop Hands-Free Weather Alerts To Ensure Safe Backpacking
  • The Ultimate API Development Guide: Strategy, Tools, Best Practices

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: