Linux Basics
Permissions & Sudo
Linux is a multi-user operating system designed for high security. Even if you are the only person using your laptop, Linux still strictly enforces rules about who can read, write, or execute a file.
The Three Permissions
Every file and folder has three basic permissions:
- Read (
r): Can you look at the contents of the file? - Write (
w): Can you modify or delete the file? - Execute (
x): Can you run the file as a program?
When you run ls -l, you'll see a string of letters on the left side that looks like this: -rw-r--r--
This string represents the permissions for the Owner, the Group, and Everyone Else.
sudo (SuperUser DO)
Sometimes you need to do something that affects the whole system, like installing software or editing a network configuration file in /etc/. A normal user doesn't have the "Write" permission for those files.
To do this, you use sudo. It temporarily elevates your privileges to the root user (the ultimate administrator who can do anything).
# This will fail (Permission Denied)
apt update
# This will succeed (will prompt for your password)
sudo apt update
With great power comes great responsibility
Never run a command with sudo unless you absolutely have to, and you know exactly what it does. Running an untrusted script with sudo can destroy your entire operating system.
The dialout Group (Crucial for Embedded)
When you plug your ESP32 into your computer, Linux creates a device file for it, usually /dev/ttyUSB0.
By default, this file is owned by the root user, and a group called dialout. Normal users (like you) do not have "Write" permission to this file. If you try to run idf.py flash, it will fail with Permission Denied because it can't write the firmware to the USB port.
You could use sudo idf.py flash, but running entire toolchains as root is a massive security risk and creates file permission nightmares in your project folder.
The Solution: Add your normal user account to the dialout group.
# Add the current user ($USER) to the dialout group
sudo usermod -aG dialout $USER
Note: You must log out of your computer and log back in for this group change to take effect.
Changing Permissions: chmod
If you write a shell script (setup.sh), it is just a text file. It does not have "Execute" permission by default. If you try to run it (./setup.sh), Linux will block you.
You use chmod (Change Mode) to modify the permissions.
# Add (+) execute (x) permission to the file
chmod +x setup.sh
# Now you can run it!
./setup.sh

