Terminal labUnit 5 · Topic 5.2

Linux permissions: ls -l and chmod

Read ls -l output and change permissions with chmod.

New to this? Read the topic first: 5.2 Protecting Applications and Data.

Simulation · Linux permissions [5.2.D.2, 5.2.D.3, 5.2.D.6, 5.2.D.7]

Permissions lab: set rwx with chmod

You are the system administrator for a clinic's Linux file server. Every file has three sets of permissions, always in the order owner, group, others, and each set is always read, write, execute.

admin@clinic-fs: /srv/clinic
admin@clinic-fs:/srv/clinic$ ls -l
total 60
-rwxrwxrwx 1 itadmin it        912 Nov  8 17:40 backup.sh
-rwxrwxrwx 1 itadmin it        604 Nov  8 17:41 kiosk.sh
-rw-rw-rw- 1 records doctors 48211 Nov  9 07:55 patients.csv
-rw-rw-rw- 1 lead    nurses   1830 Nov  9 08:02 shifts.txt
The server as you found it: every file gives others read and write (and execute on the scripts), so anyone with an account can change patient records. Fix each file below with the principle of least privilege.
Numeric method: add the values
DigitPermissionsBuilt from
0---no permissions
1--x1 execute
2-w-2 write
3-wx2 write + 1 execute
4r--4 read
5r-x4 read + 1 execute
6rw-4 read + 2 write
7rwx4 read + 2 write + 1 execute

Tasks

  1. shifts.txt (owner lead, group nurses). The owner and the nurses group can read and edit the shift list; everyone else can only read it.

    Show the answer
    admin@clinic-fs:/srv/clinic$ chmod 664 shifts.txt
    admin@clinic-fs:/srv/clinic$ ls -l shifts.txt
    -rw-rw-r-- 1 lead nurses 1830 Nov  9 08:02 shifts.txt

    Owner rw- (6), group rw- (6), others r-- (4).

  2. patients.csv (owner records, group doctors). The owner can read and edit; doctors can only read; everyone else has no access.

    Show the answer
    admin@clinic-fs:/srv/clinic$ chmod 640 patients.csv
    admin@clinic-fs:/srv/clinic$ ls -l patients.csv
    -rw-r----- 1 records doctors 48211 Nov  9 07:55 patients.csv

    Owner rw- (6), group r-- (4), others --- (0).

  3. backup.sh (owner itadmin, group it). A script. The owner and the information technology (IT) group can read, edit and run it; everyone else has no access.

    Show the answer
    admin@clinic-fs:/srv/clinic$ chmod 770 backup.sh
    admin@clinic-fs:/srv/clinic$ ls -l backup.sh
    -rwxrwx--- 1 itadmin it 912 Nov  8 17:40 backup.sh

    Owner rwx (7), group rwx (7), others --- (0).

  4. kiosk.sh (owner itadmin, group it). A script. The owner and the IT group have full access; everyone else can read and run it but not change it.

    Show the answer
    admin@clinic-fs:/srv/clinic$ chmod 775 kiosk.sh
    admin@clinic-fs:/srv/clinic$ ls -l kiosk.sh
    -rwxrwxr-x 1 itadmin it 604 Nov  8 17:41 kiosk.sh

    Owner rwx (7), group rwx (7), others r-x (5).

In ls -l output the first character is the file type (- for a file, d for a directory). A + at the end of the permissions means extra permissions are set; view them with getfacl.

Go to the topic: 5.2 Protecting Applications and Data

Was this page helpful?

No names are ever shown, and every public comment is checked by us first. Please do not include personal details. To get a reply, email [email protected].

Course map
↑ Top

Enlarged view of the selected figure