Linux on call · Chapter 14 of 30
Permissions
By the end of this chapter you can read the rwx column of ls -l, set any mode with letters or with three digits, and treat files and folders each the way they need. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Permissions and users
- 4 tasks
- Linux
- In the all labs plan
The first 2 chapters of Linux on call are free. This one comes with the all labs plan.
Why you need this
Last night the deploy failed with "Permission denied", and Bunty fixed it with chmod -R 777 app. Now every file in the app can be read, changed and run by every user on the machine, secrets.env with the payment key too. And Kabir's new start.sh, written after the 777, will not run at all:
ls -l app
total 28
-rwxrwxrwx 1 student student 46 Oct 3 16:44 README.md
-rwxrwxrwx 1 student student 38 Oct 3 16:44 deploy.sh
drwxrwxrwx 2 student student 4096 Oct 3 16:44 logs
drwxrwxrwx 2 student student 4096 Oct 3 16:44 public
-rwxrwxrwx 1 student student 60 Oct 3 16:44 secrets.env
-rwxrwxrwx 1 student student 38 Oct 3 16:44 server.js
-rw-r--r-- 1 student student 44 Oct 3 16:44 start.sh
./app/start.sh
bash: ./app/start.sh: Permission denied
You have read this column since chapter 1, but never changed it. One mode for everything is what got Bunty here: scripts, secrets, web pages and folders each need a different one.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
Make the two scripts runnable (755) and run start.sh
Make the two scripts runnable, so start.sh can run as a program.
1. Run ls -l app. Look at the first column for start.sh and deploy.sh.
2. Use chmod to set app/start.sh and app/deploy.sh to mode 755.
3. Run start.sh by its path: ./app/start.sh from the chapter folder, or ./start.sh from inside app. Do not run it with bash.
To pass: app/start.sh and app/deploy.sh have mode 755, and you ran start.sh by its path after that, in the chapter folder (or in app). A command that gave an error, like Permission denied, does not count, so run it again.
- Task 2
Lock secrets.env to you alone (600)
Lock the secrets file, so only you can read or change the payment key.
1. Run ls -l app/secrets.env. Everyone can read and write it now.
2. Use chmod to set app/secrets.env to mode 600.
3. Do not change what is inside the file.
To pass: app/secrets.env has mode 600, and it still has its PAYMENT_KEY line.
- Task 3
Undo Bunty's 777: other files 644, folders 755
Undo the 777 on everything else under app. Folders need x, but these files are not programs.
1. Set the three folders (app, app/public and app/logs) to mode 755.
2. Set the five other files to mode 644: app/README.md, app/server.js, app/public/index.html, app/public/menu.html and app/logs/app.log.
3. If this also changed the two scripts or secrets.env, set them back to 755 and 600 again.
To pass: the three folders have mode 755 and the five files have mode 644. Do not add or delete any file or folder under app. Tasks 1 and 2 must still pass.
- Task 4 · interview question
Interview: 755 written the way ls -l shows it
Interview question: how does ls -l show the mode 755?
1. Split each digit into read (4), write (2) and execute (1).
2. Write the nine letters and dashes for the user, the group and others.
3. Save them in 755.txt, in the chapter folder. A sentence around them is fine.
To pass: 755.txt has the nine letters and dashes for 755, written together with no spaces.
What you will learn
- Reading rwx: who may read, write and run a file.
- chmod with letters: add or take away single permissions.
- chmod with digits: a whole mode in three numbers.
- Files and folders: what x means on a folder, and how to set the two apart.
More in Permissions and users
Build "Permissions" yourself
Tapri’s ordering app moves onto a Linux server, and the server is now yours to run. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Linux on call are free. This one comes with the all labs plan.