element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
sudo Sergeant
  • Challenges & Projects
  • element14 presents
  • sudo Sergeant
  • More
  • Cancel
sudo Sergeant
Documents sudo Sergeant 06: File Permissions
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join sudo Sergeant to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: tariq.ahmad
  • Date Created: 9 Oct 2017 9:41 PM Date Created
  • Last Updated Last Updated: 18 Jan 2019 4:11 PM
  • Views 1882 views
  • Likes 7 likes
  • Comments 7 comments
Related
Recommended

sudo Sergeant 06: File Permissions

image

element14's The Ben Heck Show

Join the Ben Heck team every week for amazing hacks! Watch them build and mod community-inspired projects using electronics!

Back to The Ben Heck Show homepage image

sudo Sergeant
Featured Bonus Content
See All Episodes

 

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Felix discusses how file permissions work with Linux. He covers what they mean, what they’re for, and how to set them. You’ll learn to use command line to create a file and decipher user, group, and others rights. You can then add or remove permissions by CHMOD or by permission bits in octal notation.

 

 

File permissions are the most basic form of security control on a Linux based operating system. They are implemented in a manner which can be configured to grant or deny access to files. The permissions can be modified by either the one who owns the file, or the super user.  The instruction to modify the permissions can take numeric arguments or symbolic arguments.

 

Felix uses a command line example to show you how to see the permissions of a file: Typing “ls” shows you the root directory structure.

 

sergeant@raspberrypi: ~ $ ls

Desktop   Documents   Downloads Music   Pictures  Public  Templates test  Videos

image

 

He wants to go the test directory so he types the command cd test. Typing ls again shows that this directory has two directories that were previously mounted.

 

sergeant@raspberrypi: ~ $ cd test

sergeant@raspberrypi: ~ $ ls

mount0  mount 1

 

 

Next he creates a files using command line using the touch command followed by the file he is creating and uses the ls command to verify the file was created:

sergeant@raspberrypi: ~/test  $  touch testfile.text

sergeant@raspberrypi: ~/test  $ ls

mount0 mount1 testfile.txt

 

To find the file permissions of this newly created file he types in ls -l:

 

sergeant@raspberrypi: ~/test  $ ls -l

total 8

drwxr-xr-x 2 sergeant sergeant 4096 Aug 25 13:40 mount0

drwxr-xr-x 2 sergeant sergeant 4096 Aug 25 13:40 mount1

- rw-r-- r-- 1  sergeant sergeant       0 Aug 30 09:46 testfile.txt

 

For testfile.txt the information to left of the number 1 are the file permissions. The first bit in the file permissions is the file type, the next 3 are the permissions of the owner,  the following three bits are the permissions of the group, and the last three are the permissions of anybody who is either not in the group or not the owner.  The last bit is a single character that specifies alternate access methods.image

 

For instance, if you see "drwxr" it means that the file type is director, the r means that the owner can read the directory, the w means the owner can write to the directory,  and x means the owner can execute the directory (since it's a directory it doesn't really get executed). The next 3 bits are the group rights. For testfile.txt, "r--" means that the group can read this but cannot write or execute.

 

There are two ways to modify the file permissions.  They can either be done through numeric method or via a character method. With the character method, you would change the file permissions by sending the instruction chmod (change modify).  Felix suggests expanding the help anytime you have an instruction. After, using the  command "--help" Felix decides to give execution permissions to the user for the file by typing in the following command:

 

In this example, read and write are turned off execute is turned on:

sergeant@raspberrypi: ~/test  $ chmod u=+x testfile.txt

sergeant@raspberrypi: ~/test  $ ls -l

total 8

drwxr-xr-x 2 sergeant sergeant 4096 Aug 25 13:40 mount0

drwxr-xr-x 2 sergeant sergeant 4096 Aug 25 13:40 mount1

---xr-- r-- 1  sergeant sergeant       0 Aug 30 09:46 testfile.txt

In this example, read and write are added along with execute:

 

sergeant@raspberrypi: ~/test  $ chmod u=+rwx testfile.txt

sergeant@raspberrypi: ~/test  $ ls -l

total 8

drwxr-xr-x 2 sergeant sergeant 4096 Aug 25 13:40 mount0

drwxr-xr-x 2 sergeant sergeant 4096 Aug 25 13:40 mount1

-rwxr-- r-- 1  sergeant sergeant       0 Aug 30 09:46 testfile.txt

To give those same permissions to the group simply use the following command:image

sergeant@raspberrypi: ~/test  $ chmod g=+rwx testfile.txt

sergeant@raspberrypi: ~/test  $ ls -l

total 8

drwxr-xr-x 2 sergeant sergeant 4096 Aug 25 13:40 mount0

drwxr-xr-x 2 sergeant sergeant 4096 Aug 25 13:40 mount1

-rwxrwxr-- 1  sergeant sergeant       0 Aug 30 09:46 testfile.txt

To give those permissions to others you would use the following command:

sergeant@raspberrypi: ~/test  $ chmod o=+rwx testfile.txt

sergeant@raspberrypi: ~/test  $ ls -l

total 8

drwxr-xr-x 2 sergeant sergeant 4096 Aug 25 13:40 mount0

drwxr-xr-x 2 sergeant sergeant 4096 Aug 25 13:40 mount1

-rwxrwxrwx 1  sergeant sergeant       0 Aug 30 09:46 testfile.txt

To take away group permissions you would use the minus sign instead of the plus sign:

sergeant@raspberrypi: ~/test  $ chmod g=-rwx testfile.txt

sergeant@raspberrypi: ~/test  $ ls -l

total 8

drwxr-xr-x 2 sergeant sergeant 4096 Aug 25 13:40 mount0

drwxr-xr-x 2 sergeant sergeant 4096 Aug 25 13:40 mount1

-rwx---rwx 1  sergeant sergeant       0 Aug 30 09:46 testfile.txt

This is covers adding and removing permissions using the character method.  To change permissions via the numeric method you can head over to  Unix Permissions and Lookup . Select your permissions bits. We're focusing on user, group, and others.If you want to have read write execute for user group and others you would select those permissions on the page.image

sergeant@raspberrypi: ~/test $ chmod 777 testfile.txt

sergeant@raspberrypi: ~/test $ ls -l testfile.txt

-rwxrwxrwx 1 sergeant sergeant 0 Aug 30 9:46 testfile.txt

Trying again with a different numeric value changes the file permissions:

sergeant@raspberrypi: ~/test $ chmod 700 testfile.txt

sergeant@raspberrypi: ~/test $ ls -l testfile.txt

-rwx------ 1 sergeant sergeant 0 Aug 30 9:46 testfile.txt

  • numeric method
  • sudo sergeant
  • octal notation
  • file permissions
  • rpibeginner
  • character method
  • chmod
  • rpiexpert
  • command line
  • permission bits
  • sudosergeant
  • linux
  • Share
  • History
  • More
  • Cancel
  • Sign in to reply

Top Comments

  • tariq.ahmad
    tariq.ahmad over 7 years ago in reply to jackwhite+ +1
    I am by no means a Linux expert but I do have previous professional experience maintaining Linux servers, modifying file permissions on PHP files (usually through FTP but I have used command line), and…
  • shabaz
    shabaz over 7 years ago in reply to tariq.ahmad +1
    tariq.ahmad wrote: Changing file permissions can be tricky for people maintaining Linux servers for business or in another field. This is definitely true.. I've a formal qualification in one of the UNIX…
  • tariq.ahmad
    tariq.ahmad over 7 years ago in reply to koudelad +1
    Thanks koudelad ! This has been fixed!
Parents
  • koudelad
    koudelad over 7 years ago

    There is a link to sudo Sergeant episode 05 video, instead of episode 06.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • tariq.ahmad
    tariq.ahmad over 7 years ago in reply to koudelad

    Thanks koudelad !

     

    This has been fixed!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • tariq.ahmad
    tariq.ahmad over 7 years ago in reply to koudelad

    Thanks koudelad !

     

    This has been fixed!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube