>Linux 101: Using chmod and chown


When you use Linux long enough you are going to use the command line. Although nearly every command line trick can be done from a GUI front end now, there are times when the command line is the only route (headless server for example). When you have to go that route, you will be glad to have the fundamentals of the more important Linux commands under your belt. Two very important commands, chmod and chown, deal with permissions and ownership (respectively). With these tools you control who owns and who reads, writes, and executes files  and folders on your linux system . Let’s take a look at how to use these commands.
Not a bit. By default you will have both chmod and chown installed on your system.
The chmod command allows you to change permissions on a file. The basic usage is:
Where PERMISSIONS is either the numeric or the alpha equivalent of the permissions you want to assign and FILE is the file (or folder) you want to effect.
Since the numeric permissions are the easiest to understand (and use) let’s look at that method.
Remember, file permissions are in the form:
OWNER | GROUP | All Others
Each of those sections includes:
Each permission (read, write, execute) is represented with the binary representation of the initial letter:
  • r – 4
  • w – 2
  • x – 1
To get the numeric permission you add which permissions you want to use together. So if you want r+w you get 6. If you want r+w+x you get 7. If you want r+x you get 5. If you want only r you get 4. So now, remembering you have to cover permissions for three different users (Owner, Group, All Others), you will need to have a numeric number for each. So if you want Owner and Group to have rwx permission and All Others to only have r permissions, you would have:
Now, to change the permission of a particular file to 774 you would issue the command:
chmod 774 FILENAME
Where FILENAME is the name of the file.
Now let’s examine the changing of ownership. This will bite you when you install an application in a directory as one user and need to use it as another. So let’s say you have a folder in the /opt directory called APP that belongs to user bethany but user jacob needs to own it instead (of course if they both need access you could just change permissions or create a group for this). To change the ownership of this folder (you will need administrative rights to do this) you would issue a command like:
sudo chown jacob.jacob /opt/APP
http://rcm.amazon.com/e/cm?t=widgetsamazon-20&o=1&p=8&l=bpl&asins=B004CYEQF0&fc1=000000&IS2=1&lt1=_blank&m=amazon&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifrThe above command would change both ownership and group ownership of the folder (since jacob.jacob was used). If you wanted to leave that folder belonging to the original group issue the command like:
sudo chown jacob /opt/APP
and the original group ownership would remain intact.
Final thoughts
Permissions and ownership on Linux isn’t nearly as challenging as you though – even from the command line! Of course you can do these same tasks from within your file manage – if you have a file manager!

About nonerox

Btech Student
This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s