← Operating Systems from Zero: Linux, Windows and macOS

Video coming soon

The written lesson below is ready now. The video is being published on our YouTube channel.

Follow ChangeCV on YouTube →

Lesson 3 of 6

Permissions and admin rights: whoami, ls -l, chmod, chown and sudo

Understand who may do what to a file, with an office keycard analogy. Read a permission listing, change it with chmod and chown, and use sudo carefully. Includes the Windows equivalents.

The idea in plain words

Think of an office building with keycards. Each person has a card, which is your user account. Each door lists who may go in, and those are the permissions.

The building manager has a master key. That is root on Linux and macOS, and the administrator on Windows. A master key opens everything, so you borrow it only when you need it, with sudo.

Commands in this lesson

whoami
Print the user you are logged in as. On Windows it shows the computer name and the user.
ls -l deploy.sh
Show the permissions of a file: type, then read, write and execute for the owner, the group and others.
chmod +x deploy.sh
Change permissions. +x adds execute, and numbers such as 644 and 755 set them all at once. Windows has no execute bit.
sudo chown ava:ava notes.txt
Change the owner and group of a file. On macOS the default group is staff. On Windows, takeown and icacls do similar jobs.
sudo whoami
Run one command as the administrator (root). Windows has no sudo: use Run as administrator.

Written notes from the video

Why permissions matter

Ever run a command and seen the words: permission denied? That is the system protecting itself. This is Operating Systems from zero, episode three: permissions and admin rights. Five commands to see who you are, and what you are allowed to do.

The keycard analogy

Think of an office building with keycards. Each person has a card. That is your user account. Each door lists who may go in. Those are permissions. The building manager has a master key. That is root on Linux and macOS, and the administrator on Windows. A master key opens everything, so you borrow it only when you need it, with sudo.

Command 1: whoami

Command one: whoami. It prints the name of the user you are logged in as. Here, it says ava. On Windows, whoami works too. It shows the computer name and the user, like desktop-4f2k\ava.

Command 2: ls -l

Command two: ls -l. The long listing shows the permissions of a file. Read the first ten characters. The first one is the type, and a dash means an ordinary file. Then come three groups of three letters: owner, group and others. r is read, w is write, and x is execute. Here, ava can read and write deploy.sh, and everyone else can only read it.

Command 3: chmod

Command three: chmod, short for change mode. Running ./deploy.sh fails with permission denied, because the file has no x. chmod +x adds the execute permission. Now the listing shows an x for the owner, the group and others. You can also use numbers. Four is read, two is write, and one is execute. So chmod 644 means read and write for the owner, and read only for everyone else. And 755 adds execute.

Command 4: chown

Command four: chown, short for change owner. Here, notes.txt belongs to root, so ava cannot edit it. sudo chown ava:ava notes.txt makes ava the owner. sudo asks for your password once, and then runs the command as an administrator. On macOS, the default group is called staff, so the command ends with ava colon staff.

Command 5: sudo

Command five: sudo. Some system files, like the password file, are only for administrators. Reading it as a normal user says permission denied. sudo whoami answers root. That is the master key. Be careful. With sudo, you can change or delete anything.

On Windows and macOS

On Windows PowerShell, whoami works too. icacls shows who may access a file, and can grant access. Quote the permission in PowerShell. takeown takes ownership. Windows has no execute bit, and no sudo. For administrator rights, right click PowerShell, and choose Run as administrator.

Recap

Recap. whoami tells you who you are. ls -l shows permissions. chmod changes what is allowed, chown changes the owner, and sudo borrows the master key.

Next episode

Next episode: the command line. You will learn pipes, redirects, the path, and history. Subscribe so you do not miss it, and find written notes for every lesson at changecv.com/skills.

Common questions

What do the letters rwx mean?

r is read, w is write and x is execute. They appear three times in a listing, for the owner, the group and everyone else. In numbers, read is 4, write is 2 and execute is 1, so 7 means all three.

What does chmod 755 mean?

7 gives the owner read, write and execute, and each 5 gives the group and others read and execute. It is the usual setting for a script or a program that everyone may run.

Why do I get "permission denied" when I run a script?

The file probably has no execute permission. chmod +x adds it. The error can also mean that you are not allowed to read the file or the folder it is in.

Is it safe to use sudo for everything?

No. With sudo you can change or delete anything on the system, and a typing mistake can do real damage. Use it only for the one command that needs it.

How do permissions work on Windows?

Windows uses access control lists instead of the rwx letters. icacls shows and changes them, and takeown takes ownership of a file. There is no execute bit and no sudo, and you open PowerShell as administrator for admin tasks.