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$ 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
| Digit | Permissions | Built from |
|---|---|---|
| 0 | --- | no permissions |
| 1 | --x | 1 execute |
| 2 | -w- | 2 write |
| 3 | -wx | 2 write + 1 execute |
| 4 | r-- | 4 read |
| 5 | r-x | 4 read + 1 execute |
| 6 | rw- | 4 read + 2 write |
| 7 | rwx | 4 read + 2 write + 1 execute |
Builder
admin@clinic-fs:/srv/clinic$ chmod 754 report.txt admin@clinic-fs:/srv/clinic$ ls -l report.txt -rwxr-xr-- 1 lead nurses 2048 Nov 9 08:15 report.txt# the same result with the symbolic method: admin@clinic-fs:/srv/clinic$ chmod u=rwx,g=rx,o=r report.txt
Tasks
-
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), grouprw-(6), othersr--(4). -
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), groupr--(4), others---(0). -
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), grouprwx(7), others---(0). -
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), grouprwx(7), othersr-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