Microsoft Windows Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 24 May 2012

How Do Linux File Permissions Work?

Posted on 09:43 by Unknown

HTG Explains: How Do Linux File Permissions Work?

banner-01
If you’ve been using Linux for some time (and even OS X) you’ll probably have come across a “permissions” error. But what exactly are they, and why are they necessary or useful? Let’s take an inside look.

User Permissions

Back in the day, computers were massive machines that were incredibly expensive. To make the most out of them, multiple computer terminals were hooked up which allowed many users to go about their business simultaneously. Data processing and storage was done on the machine, while the terminals themselves were little more than a means of viewing and inputting data. If you think about it, it’s pretty much how we access data on the “cloud”; look at Amazon’s Cloud MP3 system, Gmail, and Dropbox, and you’ll notice that while changes can be made locally, everything is stored remotely.

(Image: Zenith Z-19 “dumb” terminal; credit: ajmexico)
In order for this to work, individual users need to have accounts. They need to have a section of the storage area allotted to them, and they need to be allowed to run commands and programs. Everyone gets specific “user permissions,” which dictates what they can and cannot do, where on the system they do and do not have access, and whose files they can and cannot modify. Each user is also placed into various groups, which grant or restrict further access.

File Access


In this wacky multi-user world, we’ve already set up boundaries as to what users can do. But what about what they access? Well, every file has a set of permissions and an owner. The owner designation, typically bound when the file is created, declares which user it belongs to, and only that user can alter its access permissions.
In the world of Linux, permissions are broken down into three categories: read, write and execute. “Read” access allows one to view a file’s contents, “write” access allows one to modify a file’s contents, and “execute” allows one to run a set of instructions, like a script or a program. Each of these categories are applied to different classes: user, group, and world. “User” means the owner, “group” means any user who is in the same group as the owner, and “world” means anybody and everybody.

Folders can also be restricted with these permissions. You can, for example, allow other people in your group to view directories and files in your home folder, but not anyone outside of your group. You will probably want to limit “write” access to only yourself, unless you’re working on a shared project of some sort. You can also create a shared directory that allows anyone to view and modify files in that folder.

Changing Permissions in Ubuntu

GUI
To change the permissions of a file you own in Ubuntu, just right-click the file and go to “Properties.”

You can change whether the Owner, Group, or Others can read and write, read only, or do nothing. You can also check a box to allow execution of the file, and this will enable it for the Owner, Group, and Others simultaneously.
Command-Line
You can also do this via the command-line. Go to a directory that has files in it and type the following command to view all files in a list:
ls -al

Next to each file and directory, you’ll see a special section that outlines the permissions it has. It looks like this:
-rwxrw-r–
The r stands for “read,” the w stands for “write,” and the x stands for “execute.” Directories will be start with a “d” instead of a “-“. You’ll also notice that there are 10 spaces which hold value. You can ignore the first, and then there are 3 sets of 3. The first set is for the owner, the second set is for the group, and the last set is for the world.
To change a file or directory’s permissions, let’s look at the basic form of the chmod command.
chmod [class][operator][permission] file
chmod [ugoa][+ or –] [rwx] file
This may seem complicated at first, but trust me, it’s pretty easy. First, let’s look at the classes:
  • u: This is for the owner.
  • g: This is for the group.
  • o: This is for all others.
  • a: This will change permissions for all of the above.
Next, the operators:
  • +: The plus sign will add the permissions which follow.
  • -: The minus sign will remove the permissions which follow.
Still with me? And the last section is the same as when we checked the permissions of a file:
  • r: Allows read access.
  • w: Allows write access.
  • x: Allows execution.
Now, let’s put it together. Let’s say we have a file named “todo.txt” that has the following permissions:
-rw-rw-r–
That is, the owner and group can read and write, and the world can only read. We want to change the permissions to these:
-rwxr—–
That is, the owner has full permissions, and the group can read. We can do this in 3 steps. First, we’ll add the execution permission for the user.
chmod u+x todo.txt
Then, we’ll remove the write permission for the group.
chmod g-w todo.txt
Lastly, we’ll remove the read permissions for all other users.
chmod o-r todo.txt
We can also combine these into one command, like so:
chmod u+x,g-w,o-r todo.txt

You can see that each section is separated by commas and there are no spaces.
Here are some useful permissions:
  • -rwxr-xr-x : Owner has full permissions, group and other users can read file contents and execute.
  • -rwxr–r– : Owner has full permissions, group and other users can only read file (useful if you don’t mind others viewing your files.
  • -rwx—— : Owner has full permissions, all others have none (useful for personal scripts).
  • -rw-rw—-: Owner and group can read and write (useful for collaboration with group members).
  • -rw-r–r– : Owner can read and write, group and other users can only read file (useful for storing personal files on a shared network).
  • -rw——- : Owner can read and write, all others have none (useful for storing personal files).
There are a few other things you can do with chmod – like setuid and setgid – but they’re a little in-depth and most users won’t really need to use them anyway.

The Root or Super-User and System Files


Nowadays, we don’t always run systems that have multiple users. Why should we still worry about permissions?
Well, Unix and its derivatives – Linux, OS X, among others – also distinguish between things run by the user, things run by an administrator or with admin privileges, and things run by the system itself. As such, things that are integral for the system need admin privileges to be changed or accessed. This way, you don’t mess up anything accidentally.
In Ubuntu, to make changes to system files you use “sudo” or “gksudo” to gain the equivalent of Administrator privileges. In other distros, you switch to “root” or the “super-user” which effectively does the same thing until you log out.
Be aware that in both of these circumstances, changing file permissions can lead to programs not working, unintentionally changing file ownership to the root user (instead of the owner), and making the system less secure (by granting more permissions). As such, it’s recommended you don’t change permissions for files – especially system files – unless it’s necessary or you know what you’re doing.


File permissions are in place to provide a basic system of security amongst users. Learning how they work can help you set up basic sharing in a multi-user environment, protect “public” files, and give you a clue as to when something goes wrong with system file ownership.

Related Article: Install an RPM Package on Ubuntu Linux
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • how linux is built
  • Samsung Electronics has bought Boxee
    Samsung Electronics has confirmed its purchase of Boxee on Wednesday for its  smart TVs .  Samsung plans to use this acquisition as a way to...
  • Another Microsoft Guru Steps Down
    Microsoft announced on Monday that company veteran Craig Mundie has stepped down from his post as chief of research and will retire in th...
  • Dr. Dre Top As The New Hip-Hop’s Top Earner
    Six years ago Dr. Dre was walking   for more click here
  • Microsoft new Windows, tablet
    US computing giant Microsoft on Tuesday gave an early peek to the key Chinese market of its new tablet computer and Windows 8 software, pr...
  • Thought words
    “ Greatness lies not in being strong, but in the right using of strength. ” — Henry Ward Beecher
  • How to Move Your Email to Another Mac
    If you use Apple's Mail application, there will probably come a time when you'll want to move your email messages and email account...
  • How To SSH Hop With Key Forwarding from Windows
    In this guide we’ll explain how to SSH to a Linux machine from Windows with your public key, using Putty & Winscp. In addition, we wil...
  • Japan's largest solar and wind power project breaks ground
    Seven Japanese companies have been celebrating the ground breaking of their solar and wind power project at a ceremony held today at the ...
  • How to Recover a Deleted File
    It’s happened to most of us. You delete a file and realize you need it back. This guide will explain when you can get that file back and how...

Categories

  • 3 D printers
  • 360s
  • amazon
  • android
  • animation
  • apple
  • bing
  • book
  • boxee
  • browser
  • china
  • chrome
  • console
  • dicaprio
  • domain
  • ecommerce
  • facebook
  • ferrari
  • finland
  • gadget
  • galaxy
  • games
  • gmail
  • google
  • hosting
  • HTC
  • internet
  • ipad
  • iphone
  • iphoto
  • iwatch
  • japan
  • keyborad
  • lenovo
  • linux
  • lunar
  • microsoft
  • mobile
  • moon
  • movil
  • ms
  • names
  • new tech
  • Nokia
  • online
  • password
  • pc
  • phone
  • retails
  • samsung
  • search
  • smartphone
  • software
  • space
  • tablet
  • tech
  • text messages
  • track
  • trip
  • usres
  • web
  • whatsapp
  • whois
  • window
  • words
  • xbox

Blog Archive

  • ►  2013 (160)
    • ►  December (1)
    • ►  November (9)
    • ►  September (5)
    • ►  August (8)
    • ►  July (19)
    • ►  June (12)
    • ►  May (23)
    • ►  April (3)
    • ►  March (5)
    • ►  February (18)
    • ►  January (57)
  • ▼  2012 (340)
    • ►  December (25)
    • ►  November (34)
    • ►  October (24)
    • ►  September (27)
    • ►  August (26)
    • ►  July (46)
    • ►  June (83)
    • ▼  May (42)
      • Final test version of Windows 8 released
      • The Pros And Cons Of Using Cloud Hosting
      • China: The world's cleverest country?
      • 40 percent of Germany’s electricity demand this we...
      • Samsung to start selling Galaxy S3 in 28 nations
      • Britain : Do UK need an Aircraft Carrier?
      • Facebook is making a phone, are you aware?
      • Browser wars flare in mobile space
      • Yahoo! ditches digital newsstand for iPads
      • China fund may help Alibaba in Yahoo! bid: report
      • The Growing Vietnam's new technology entrepreneurs...
      • Installing an RPM Package on Ubuntu Linux
      • How Do Linux File Permissions Work?
      • Google in patent fight with Oracle
      • Are the police tracking your calls?
      • Is China becoming the biggest app market for smart...
      • Sheryl Sandberg, the Woman Behind Facebook's Busin...
      • Microsoft launches has lauched its own facebook
      • is Google chrome overtaking internet explorer as #...
      • Uk cities to get Super - connected
      • Japan Lunches SouthKorea Satellite
      • Alibaba buys half of Yahoo stake for $7.1bn
      • Facebook First Female Engineer
      • Facebook founder Mark Zuckerberg Wed His Long time...
      • Knowing How To Connect a Bluetooth Keyboard to an ...
      • Knowing How to Change Your Mac's DNS Servers
      • UK: British surveillance program To expose private...
      • Internet: China mobile online user top 1.1billion
      • see how people uses facebook by numbers
      • World cheapest computer priced at $25. Will it rev...
      • facebook has made Bono, the richest musician in th...
      • will facebook becomes the first trillion dollars c...
      • Face has added 84 Million More Shares For Sale
      • Will Facebook IPO bring cash and changes to the c...
      • Knowing How to Change Your IP Address Using PowerS...
      • Facebook plans to start charging you money for you...
      • Is Facebook ahead IPO excitement creating intensity?
      • Youtube: Do video sharing app demise youtube?
      • FACEBOOK:will you give up your citizenship just be...
      • 'Angry Birds' Game Maker to Lunch a New Game calle...
      • music-movie streaming firm mSpot, is being bought ...
      • Facebook buys Glancee a mobile discovery startup
    • ►  April (33)
Powered by Blogger.

About Me

Unknown
View my complete profile