How to view and change permissions

Overview

Linux permissions control reading, writing, and executing for the owner, group, and others. Directories need execute permission to be entered.

View and change

ls -l script.sh
chmod u+x script.sh
chmod 644 notes.txt
chmod 755 script.sh
chown user:group file.txt

Modes explained

  • r, w, and x mean read, write, and execute
  • u, g, and o mean user, group, and others
  • 644 is common for readable, owner-writable files
  • 755 is common for executable scripts and public directories
  • 700 keeps access with the owner

Safety

Do not solve permission problems with chmod 777; it grants everyone broad access. Identify which user or group needs which permission.

chown usually needs sudo and changes ownership. Use it only when the desired owner is clear.