Dev / Ubuntu

File and Directory Permissions and What They Mean

When you ls -la or ls-la a directory or file there’s these characters at the left column like drwxr-xr-x or -rw-rw-rw-. So what do they mean?

Basically they’re permissions about who can read, write, and execute your files and directories.

What do they mean?

Heres the breakdown:

d rwx rwx rwx
d means it's a directory
the 3 rwx sections are permissions for the owner, group, and all.
r means read, w means write, x means execute or run.

Here are some examples:

-rwxrw-r--  This means that it's a file, the owner can read write and
            execute, the group can read and write, and everyone else
            can only read.

dr--r--r--  This means it's a directory and the owner, group and
            everyone can only read.

-r--------  This means that nobody can do anything to this file except
            the owner who can read it.

Got it?

Sometimes I see 777, 644, 444!

Don’t panic. It’s exactly the same thing! This is the octal display of the permissions.

Here’s the breakdown:

777  the 3 numbers represent permissions for
     owner, group, and all respectively
745  7 is for the owner, 4 is for the owner, 5 is for the group

What do the numbers mean? Basically it’s a sum.

4 read (r)
2 write (w)
1 execute (x)

So you add to get the number. To quote from this article:

So, try wrapping your head around this!!

7 = 4+2+1 (read/write/execute)
6 = 4+2 (read/write)
5 = 4+1 (read/execute)
4 = 4 (read)
3 = 2+1 (write/execute)
2 = 2 (write)
1 = 1 (execute)

400 read by owner
040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody

666 read/write by anybody! (the devil loves this one!)
755 rwx for owner, rx for group and rx for the world
777 read, write, execute for all! (may not be the best plan in the world…)

So how do I change permissions? CHMOD

Using man chmod:

chmod – change file mode bits

Change permissions by using the rwx notation:

chmod +w myfile.txt adds write permissions to owner, group and all
chmod o+r myfile.txt adds read permissions to the owner
chmod a+rwx myfile.txt adds read, write, and execute permissions to all
chmod g-r myfile.txt removes read permissions to the group

Change permissions by using the octal version:

chmod 777 myfile.txt
chmod 400 myfile.txt
chmod 755 myfile.txt
chmod 644 myfile.txt
chmod 211 myfile.txt

So go ahead and figure out what the above commands mean.

This is essential to learn for basic security. 🙂 Good luck!

Oh and for the newbies, this is not only with Ubuntu. It’s in general when you use Terminal. 🙂 And if you’re chmod won’t work then sudo it!


One thought on “File and Directory Permissions and What They Mean

Leave a Reply

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

You are commenting using your 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