Base permissions and the role of umask
Every new file receives base permissions of read and write for owner, group, and others. Directories receive read, write, and execute for all three. These values equal 666 for files and 777 for directories in octal notation.
The umask setting reduces these base values. A common umask of 022 removes write permission for group and others, resulting in 644 for files and 755 for directories. Administrators can view the current umask by running umask and change it temporarily with umask 027 for stricter group access.
- Read permission (4) lets users view file contents or list directory entries.
- Write permission (2) allows modification of file contents or creation and deletion inside directories.
- Execute permission (1) permits running files as programs or traversing directories with cd.
Changing permissions with chmod
The chmod command updates permissions after files exist. Symbolic mode uses letters for who, an operator, and the permission letter. Numeric mode uses three octal digits that directly set the three ownership levels.
For example, chmod u=rw,g=r,o= file.txt grants the owner read and write while giving the group only read access. The same result in numeric form is chmod 640 file.txt. When working with directories that multiple people must use, chmod 2770 shared/ adds the setgid bit so new files inherit the group owner.
- chmod a+r file adds read permission for everyone.
- chmod g-w file removes write permission from the group.
- chmod 755 script.sh sets owner full access and others read plus execute.
Ownership with chown and chgrp
Permissions apply to the owner, the group, and everyone else. The chown command transfers ownership to another user. The chgrp command changes only the group. Both commands accept the -R flag to act recursively on directories.
When a directory must be writable by several users without giving them ownership of each other's files, create a dedicated group, add members with usermod, then set the directory group and permissions accordingly. New files created inside inherit the directory group only when the setgid bit is present.
- chown user:group path changes both owner and group at once.
- chgrp developers reports/ updates the group without touching the owner.
- ls -ld directory shows the current owner, group, and permission string.
Practical directory setups for teams
Shared project directories benefit from a dedicated group and the setgid bit. First create the group, then mkdir project, chown root:project project, chmod 2770 project. Members of the project group can now create files that stay owned by the project group.
For cases where only a subset of files should be readable by others, keep the directory at 2770 and adjust individual files with chmod 640 or 660 after creation. This approach prevents accidental exposure while still allowing necessary collaboration.
- Avoid 777 on any production directory.
- Use 755 for directories that only need to be traversed and read.
- Test access by switching to each target user account with su or sudo -u.
Verification and ongoing maintenance
After any change, run ls -l or ls -ld to confirm the permission string, owner, and group. The find command can locate files with overly permissive settings such as find /path -perm -o=w. Regular audits help maintain least privilege as projects evolve and team membership changes.
Remember that execute permission on a directory only grants traversal. Without read permission, users cannot list contents even if they can cd into the directory. Combine both rights when listing is required.
- ls -l shows the permission string, owner, group, and name.
- find . -perm 777 lists world-writable items that may need tightening.
- getfacl path displays any extended ACL entries that supplement standard permissions.