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.