Admin Rights & Permissions
Most of what you do in a terminal only touches your own files, so it runs with your normal, limited rights. Some tasks change the whole machine: installing software for all users, editing system settings, starting services, writing to C:\Program Files or /usr. Those need administrator rights (Windows) or root rights (Linux, macOS). This lesson shows how each OS grants them safely, and how file permissions decide who may read, change or run a file.
The principle: run with less, elevate on demand
Modern systems log you in as a normal user even if your account is an administrator. You elevate only for the one command or window that needs it, so a typo or a malicious script can't silently damage the system.
normal rights elevated rights
Windows PowerShell / CMD window --UAC--> "Administrator: ..." window
Linux ada@ubuntu:~$ command --sudo--> same command run as root
macOS ada@macbook ~ % command --sudo--> same command run as rootWindows: Run as administrator and UAC
On Windows, elevation applies to a whole window (process), not a single command. Ways to open an elevated terminal:
- Right-click Terminal (or Command Prompt / PowerShell) in the Start menu → Run as administrator.
- Press
Win+X, then choose Terminal (Admin). - From an existing PowerShell:
Start-Process pwsh -Verb RunAs. - In Windows Terminal: hold
Ctrl+Shiftwhile clicking a profile.
Each of these triggers UAC (User Account Control): the screen dims and asks you to confirm (or for an admin password if your account is a standard user). The new window's title starts with Administrator: and it starts in C:\Windows\System32.
Without elevation, system changes fail with an access denied error:
C:\Users\ada>net stop spooler
System error 5 has occurred.
Access is denied.PS C:\Users\ada> Stop-Service Spooler
Stop-Service: Service 'Print Spooler (Spooler)' cannot be stopped due to the following error: Cannot open Spooler service on computer '.'.To check whether the current PowerShell window is elevated:
PS C:\Windows\System32> $id = [Security.Principal.WindowsIdentity]::GetCurrent()
PS C:\Windows\System32> ([Security.Principal.WindowsPrincipal]$id).IsInRole('Administrators')
TrueWindows 11 (24H2 and later) also offers a built-in sudo command, which you can enable in Settings → System → For developers. It runs a single command elevated after a UAC prompt, e.g. sudo netstat -ab. It is not the same program as Linux's sudo, and it is off by default.
Linux & macOS: sudo
On Linux and macOS you stay in your normal shell and put sudo in front of one command. It asks for your own password (not root's), remembers it for a few minutes, and logs what you ran:
ada@ubuntu:~$ apt install htop
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock, are you root?
ada@ubuntu:~$ sudo apt install htop
[sudo] password for ada:
...
ada@ubuntu:~$ sudo whoami
rootOnly users in the admin group (sudo on Ubuntu, wheel on Fedora, admin on macOS) may use sudo. Two traps to know:
sudo echo text > /etc/filefails, because the redirection is done by your own, unprivileged shell. Useecho text | sudo tee /etc/fileinstead.sudo -iorsudo sugives you a full root shell. Leave it withexitas soon as you're done; a root prompt usually ends in#instead of$.
Who am I? These commands work without any special rights:
whoami
id -un
id -ulearner
learner
1000
@echo off
echo %USERNAME% on %COMPUTERNAME%
echo %USERDOMAIN%\%USERNAME%learner on TAD
TAD\learner
On a real PC, whoami prints the same pair in lower case (sample output, yours will differ):
C:\Users\ada>whoami
desktop-7q2k4lm\adaUser ID 0 is always root on Linux and macOS; a normal user has a number of 1000 or more on Linux (501 or more on macOS).
File permissions
Besides "admin or not", every file says who may do what with it. The two families work differently.
Linux & macOS: owner, group, others
Each file has an owner, a group and three sets of r (read), w (write) and x (execute) bits: one for the owner, one for the group, one for everyone else. ls -l shows them, and chmod changes them, either with letters or with octal digits (r=4, w=2, x=1):
printf '#!/bin/sh\necho hello from the script\n' > hello.sh
printf 'secret\n' > notes.txt
stat -c '%A %n' hello.sh notes.txt
chmod +x hello.sh # add execute for everyone
chmod 600 notes.txt # rw for the owner, nothing for others
stat -c '%A %a %n' hello.sh notes.txt
./hello.sh-rw-r--r-- hello.sh
-rw-r--r-- notes.txt
-rwxr-xr-x 755 hello.sh
-rw------- 600 notes.txt
hello from the script
Reading -rwxr-xr-x: the first character is the type (- file, d directory), then rwx for the owner, r-x for the group and r-x for others. Without the x bit, ./hello.sh would fail with Permission denied: that's why every new shell script needs chmod +x (see Your First Script on Each OS). chown changes the owner and needs sudo. (macOS uses stat -f '%Sp %N' instead of GNU's stat -c; ls -l works on both.)
Windows: ACLs
Windows files don't have execute bits: whether a file runs depends on its extension (.exe, .bat, .ps1). Instead, NTFS stores an access control list (ACL): a list of users and groups, each with rights such as Read (R), Modify (M) or Full control (F). In Explorer it's Properties → Security; in the terminal it's icacls (CMD) or Get-Acl (PowerShell):
C:\Users\ada>icacls notes.txt
notes.txt NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Administrators:(I)(F)
LAPTOP-ADA\ada:(I)(F)
Successfully processed 1 files; Failed processing 0 files
C:\Users\ada>icacls notes.txt /inheritance:r /grant:r ada:F
processed file: notes.txt
Successfully processed 1 files; Failed processing 0 files(I) means the right is inherited from the parent folder, (F) is full control. The second command removes inherited rights and leaves only ada with access, roughly what chmod 600 does on Linux.
PS C:\Users\ada> (Get-Acl notes.txt).Access | Format-Table IdentityReference, FileSystemRights
IdentityReference FileSystemRights
----------------- ----------------
LAPTOP-ADA\ada FullControlComparison
| Task | Windows | Linux | macOS |
|---|---|---|---|
| Elevate | Run as administrator (UAC), Win 11 sudo |
sudo cmd |
sudo cmd |
| Root/admin shell | admin terminal window | sudo -i |
sudo -i |
| Who am I | whoami |
whoami, id |
whoami, id |
| Show permissions | icacls f, Get-Acl f |
ls -l f |
ls -l f |
| Change permissions | icacls f /grant user:M |
chmod 640 f |
chmod 640 f |
| Change owner | icacls f /setowner user |
sudo chown user f |
sudo chown user f |
| Make runnable | give it the right extension | chmod +x f |
chmod +x f |
Rule of thumb: if a command fails with Access is denied or Permission denied, first ask whether it really should touch system files. If yes, elevate for that command only. Never "fix" permission errors with chmod 777 or by running everything as admin.
Learn more: Linux Permissions, chmod & chown, CMD Admin Tasks, Windows Security.
Test yourself
On Windows, what does elevation apply to?
- A single command
- A whole process/window
- Only the current folder
- The whole user session until logout
What does chmod 600 notes.txt do?
- Everyone can read and write
- Only the owner can read and write
- Makes it executable
- Gives the file to root
Why does sudo echo hi > /etc/motd fail for a normal user?
- echo can't run as root
- The redirection is done by the unprivileged shell
- /etc is read-only
- sudo needs -i