What Is chmod? Changing File Permissions
chmod (change mode) is the Unix command that modifies a file's permission bits, controlling who can read, write, or execute it.
chmod is how you change file permissions on Unix. You might make a script runnable, lock a secrets file down, or open a directory up. In CI, the most common use is chmod +x to add the execute bit to a script so it can be run directly, fixing a frequent "permission denied" error.
What chmod does
chmod sets the read, write, and execute bits on a file for the owner, group, and others. It accepts either symbolic notation (like +x) or numeric octal notation (like 755).
Symbolic notation
chmod +x script.shadds the execute bit for all classes.chmod u+w fileadds write for the owner only.chmod go-r secretremoves read for group and others.
Numeric notation
Numeric mode sets all bits at once: chmod 755 script.sh gives rwx to the owner and r-x to group and others, while chmod 600 key restricts a private key to owner read and write only.
Recursive changes
Adding -R applies chmod to a directory tree. Use it carefully: chmod -R 777 on a project is a security smell, granting everyone full access to every file.
chmod in CI
When a step runs ./build.sh and hits "permission denied," adding chmod +x build.sh first usually fixes it. Better still, commit the file with the execute bit set so the chmod is unnecessary.
Fixing permissions on managed runners
On Latchkey runners, chmod +x reliably makes a script executable within a step. For sensitive files like keys written during a job, use restrictive modes such as 600 to limit access.
Key takeaways
- chmod changes a file's read, write, and execute permission bits.
- It accepts symbolic (
+x) or numeric (755) notation. - In CI,
chmod +xis the common fix for a non-executable script.