Sikau

Linux and the shell · Day 11 · about 35 min

Users and permissions

rwx, chmod, chown, sudo and groups.

Who may do what

Linux is multi-user: every file has an owner, a group, and permissions for three audiences — the owner (u), the group (g) and everyone else (o). That's why you can't read /etc/shadow, and why a leaked web server can't delete your home folder.

Reading and changing permissions

id
ls -l /etc/passwd /etc/shadow
cat /etc/shadow
sudo cat /etc/shadow
touch deploy.sh secret.txt
ls -l deploy.sh
chmod u+x deploy.sh
chmod 600 secret.txt
ls -l deploy.sh secret.txt
mkdir shared
sudo chown asha:developers shared
sudo chmod 775 shared
ls -ld shared
  • 644 — files: owner writes, everyone reads
  • 755 — scripts and directories
  • 600 — private keys and secrets
  • 777 — almost never: everyone can change it

The rest of this lesson

  • Reading ls -lexplain
  • sudo with careexplain
  • Decode itpredict
  • Numeric modesmatch
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 16 lessons of Linux and the shell