Linux File Permissions 101

Everything is a file

Linux is a multi-user OS

Users, groups and others

Read, Write & Execute

Implementation

          aaron@kratos:~/tmp$ ls -l
          -rw-r--r--  1 aaron web        15 Sep 20 19:39 bar.html
          -rwxr-xr--  1 aaron aaron     510 Sep 20 19:39 foo.sh
          drwxr-xr-x  2 aaron admin    4096 Sep 20 19:39 stuff
        

Implementation

          -rw-r--r--   1 aaron web       15 Sep 20 19:39 bar.html
  
            -      rw-    r--     r--
          (type) (user) (group) (other)
        

Type:

Implementation

          -rw-r--r--   1 aaron web       15 Sep 20 19:39 bar.html
  
            -      rw-    r--     r--
          (type) (user) (group) (other)
        

Access:

Implementation

          -rw-r--r--   1 aaron web       15 Sep 20 19:39 bar.html
  
            1     aaron    web
         (links)  (user) (group)
        

Links:

Owners:

Implementation

          -rw-r--r--   1 aaron web       15 Sep 20 19:39 bar.html
  
              15       Sep 20 19:39    bar.html
          (byte size) (modified date) (filename)
        

Size:

Date:

Filename:

Change permissions

chmod:

chown:

chgrp:

Change permissions

chmod:

          -rw-r--r--  1 aaron aaron     15 Sep 20 19:39  file1.txt
        

Demonstration

Change permissions

chmod:

          -rw-r--r--  1 aaron aaron     15 Sep 20 19:39  file1.txt
        

Demonstration

Change permissions

chown:

          -rw-r--r--  1 aaron aaron     15 Sep 20 19:39  file1.txt
          chown bob file1.txt
          -rw-r--r--  1 bob   aaron     15 Sep 20 19:39  file1.txt
        

Change permissions

chgrp:

          -rw-r--r--  1 aaron aaron     15 Sep 20 19:39  file1.txt
          chgrp web file1.txt
          -rw-r--r--  1 aaron web       15 Sep 20 19:39  file1.txt
        

Quiz Time!

  1. What is the numerical chmod of -rwxrw-r-x?
    • Answer: 765
  2. Using chmod, how do I change permissions so owner has read/write, group has read and other has no permissions?
    • Answer: chomd 640
    • Answer: chmod u+rw,g+r,o-rwx

Quiz Time!

  1. Can an 'other' user create a file if its parent directory permissions are drwxrw-r--?
    • Answer: no
  2. Given the permissions ----rwxrwx, can the owner of the file read, write and/or execute the file?
    • Answer: no

Priorities

          ----rwxrwx  1 aaron aaron     15 Sep 20 19:39  file1.txt
        
  1. Owner FIRST
  2. Group SECOND
  3. Other LAST

Demonstration

4th Permission

          aaron@kratos:~$ ls -l
          -------r--  1 aaron aaron      5 Sep 20 19:39  file1.txt
        

Sticky Bit

          aaron@kratos:~$ ls -l /
          ...
          drwxrwxrwt 16 root  root    4096 Sep 20 19:39  tmp
          ...
        

Setting Sticky Bit

4th permission:

Demonstration

SGID

Setting SGID

4th permission:

          root@kratos:/home/aaron/tmp# ls -l
          drwxr-xr-x  2 root  root    4096 Sep 20 19:39  foo
          root@kratos:/home/aaron/tmp# chmod 2777 foo
          root@kratos:/home/aaron/tmp# ls -l
          drwxrsxrwx  2 root  root    4096 Sep 20 19:39  foo
          root@kratos:/home/aaron/tmp# su aaron
          aaron@kratos:~/tmp$ touch file.txt
          aaron@kratos:~/tmp$ ls -l
          -rw-r--r--  1 aaron root       0 Sep 20 19:22  file.txt
        

SUID

Setting SUID

4th permission:

          root@kratos:/home/aaron/tmp# ls -l
          drwxr-xr-x  2 root  root    4096 Sep 20 19:39  foo
          root@kratos:/home/aaron/tmp# chmod 4777 foo
          root@kratos:/home/aaron/tmp# ls -l
          drsxrwxrwx  2 root  root    4096 Sep 20 19:39  foo
          root@kratos:/home/aaron/tmp# su aaron
          aaron@kratos:~/tmp$ touch file.txt
          aaron@kratos:~/tmp$ ls -l
          -rw-r--r--  1 aaron aaron      0 Sep 20 19:22  file.txt
        

SUID- What's the point?

Umask

Umask

          aaron@kratos:~$ mkdir foo
          aaron@kratos:~$ touch bar
          aaron@kratos:~$ ls -l
          -rw-r--r--  1 aaron aaron      0 Sep 20 19:22  bar
          drw-r-xr-x  2 aaron aaron   4096 Sep 20 19:22  foo
        

Umask- watch out!

          aaron@kratos:~$ mkdir foo
          aaron@kratos:~$ touch bar
          aaron@kratos:~$ ls -l
          -rw-----w-  1 aaron aaron      0 Sep 20 19:22  bar
          drw-----wx  2 aaron aaron   4096 Sep 20 19:22  foo
        

Umask- what's happening?

That's All Folks!

Any questions, thoughts, comments or rude remarks?

Contact me

Aaron Toponce