โ† Operating System Basics: From Zero to Hero
Level 3 ยท Hero: Power Moves

Users, Permissions and Staying Safe

Lesson 13 of 14 ยท โฑ 13 min

Many people can share one computer. So the OS needs to know who is who, and what each person is allowed to do. Linux does this very clearly, and you can see it. ๐Ÿ”’

Three kinds of accounts: administrator can change anything, standard user can use apps and keep their own files, guest can only borrow the computer.

๐Ÿงช Lab 1: who are you?

whoami
id
groups
  • id shows your user ID, your main group, and every group you are in.
  • Groups help the OS give a whole team the same permissions.
who

This lists the people logged in right now.

๐Ÿงช Lab 2: read a permission line

cd ~/MagiLab
touch diary.txt
ls -l diary.txt

You'll see a line like this:

An ls -l line labelled: file type, owner permissions, group permissions, others' permissions, owner, group, size, date and name.

-rw-r--r-- 1 magi magi 0 Nov 10 08:30 diary.txt

Break it down:

Part Meaning
- A normal file (d would mean a folder)
rw- The owner may read and write
r-- The group may only read
r-- Everyone else may only read
magi magi The owner's name and the group's name

The letters mean: r = read (look), w = write (change), x = execute (run).

๐Ÿ”Ž Your line might look a little different. On Ubuntu, new files often start as -rw-rw-r--, which means the group may write too. On Raspberry Pi OS they usually start as -rw-r--r--. Both are fine, because the idea is the same.

A secret diary file: the owner can read and write, family can only read, everyone else can do nothing.

๐Ÿงช Lab 3: lock your diary

Right now, anyone can read your diary. Let's make it private:

echo "Dear diary, Linux is awesome!" > diary.txt
chmod 600 diary.txt
ls -l diary.txt

Now it shows -rw-------: only you can read and write it! The numbers are a shortcut: 6 = rw-, 0 = ---.

Number Letters Meaning
7 rwx read, write and run
6 rw- read and write
4 r-- read only
0 --- nothing

Try a read-only diary:

chmod 400 diary.txt
echo "one more line" >> diary.txt

You'll get Permission denied, even though it's your own file! Permissions protect you from your own mistakes, too. Put the permission back:

chmod 600 diary.txt
echo "one more line" >> diary.txt
cat diary.txt

๐Ÿงช Lab 4: scripts need permission to run

Remember chmod +x? Look at your script:

ls -l hello.sh

You'll see an x in the line: it has execute permission. Without it, ./hello.sh would say Permission denied.

๐Ÿงช Lab 5: meet sudo (with a grown-up)

Try reading the file that stores secrets:

ls -l /etc/shadow
cat /etc/shadow

Permission denied, because only root (the all-powerful administrator) may read it. sudo means "do this as the super user". A grown-up can do a harmless test:

sudo whoami

It says root. Never use sudo on commands you don't understand, and never run a command that combines sudo with rm -r. It can erase a whole computer.

๐Ÿ‘‘ Standard user vs administrator: it's safest to work as a standard user, and only borrow admin powers with sudo when a grown-up says so.

๐Ÿงช Lab 6: updates (look, don't touch)

apt list --upgradable 2>/dev/null | head

This shows which programs have updates waiting. Updates fix bugs and security holes that bad programs try to sneak through. A grown-up can apply them with sudo apt update and sudo apt upgrade.

Stay safe: the hero habits

  • ๐Ÿ”‘ Strong passwords. Long, mixed, like Purple-Rocket-Pizza-42! Never share them.
  • ๐Ÿ”„ Install updates.
  • ๐Ÿค” Think before you click. Tricky messages that pretend to be someone else are called phishing.
  • ๐Ÿ”’ Lock your screen when you walk away.
  • ๐Ÿ’พ Back up the files you love.

๐Ÿ›ก๏ธ The OS is the guard, but you are the hero who makes smart choices.

Words to know

Word What it means
Permission A rule about who can read, change or run a file
Root The all-powerful administrator account
sudo Borrow root powers for one command
Phishing A trick message that tries to fool you into giving away secrets

๐ŸŽฏ Quiz time!

1. In -rw-r--r--, who can write to the file?
2. What does chmod 600 secret.txt do?
3. What does sudo do?
4. Which password is the strongest?