chmod

This will teach you how to use chmod in unix/linux terminals.

Chmod allows users to set how much (or how little) access will be permitted on a file

If you go into a folder with files in it and type the command “ls -la” you will see something like this:

drwxr-xr-x 4 chi chi 4096 2010-11-14 16:52 .
-rwxr–r– 1 chi chi 1664 2010-11-11 20:55 display.py
-rw-r–r– 1 chi chi 3229 2010-11-13 23:24 display.pyc

The “d” stand for directory or folder. “r” stands for readable. “w” meads writable. and “x” stands for executable. The first “chi” is the user, this is the owner of the file or folder. the second “chi” is the group, groups are another lesson, but for short another example of a group would be “admin”, “user”, or “root”. The rest is the last access and file name.

As seen here:

-rwxrw-r– 1 chi chi 1664 2010-11-11 20:55 display.py

The first set, “rwx”, is the user permissions or the person who owns the file/folder. This is saying, the owner, “chi” has permission to read, write and execute file “display.py”. Next “rw-” is the groups permissions. This says that the group is only allowed to read and edit the file, but not execute. The last pair “r–” says that guests may only read the file. Most times you want guests to have read only. Guests (such hackers) should not have full permissions cause it can cause the owner of a computer to have issues.

Now that we understand how to read “ls -la” and the permissions behind it, you might be wondering how do i edit these permissions. Lets learn!

We use the chmod command to change the access mode of a file. This command comes in many flavors, but we’ll be talking primarily about one of them.

chmod who=permissions filename

This gives “who” the specified permissions for a given filename.

Who

The “who” is a list of letters that specifies whom you’re going to be giving permissions to. These may be specified in any order.

Letter Meaning
u The user who owns the file (this means “you.”)
g The group the file belongs to.
o The other users
a all of the above (an abbreviation for ugo)

then we use our previously learned r,w,x keywords.

First, let’s prevent outsiders from executing display.py

Before: -rwxr-xr-x  display.py
Command: chmod o=r archive.sh
After: -rwxr-xr--  display.py 

 

Want to test it out online? Check this site out:

http://catcode.com/teachmod/try_1.html

Advertisements