Every directory or file in the Linux file system contains settings for who can read, write or execute the file. These settings are called permissions. Each file or directory is assigned to a specific user and group.
Each file or directory has 3 security groups…
- Owner (Each file or directory has a specific owner or creator)
- Group Access (Each file or directory is assigned to a specific group)
- All Others (If a user is not the owner or is not assigned to the group, they are considered in the other category)
Each security group has 3 flags that control the access status
- Flag 1 = read
- Flag 2 = write
- Flag 3 = execute (pertains to shell scripts or execute programs only)They are listed as ‘rwx‘ or a “–” if the access is turned off.
To view the permissions, you use the ls -l command. For each file or directory listed, you will see the permissions, owner and group name, and file or directory name.
|Examples||What it means|
|-rwxrwxrwx||read, write and executable for owner, group and all others|
|-rwxrwx—||read, write and executable for owner, group only|
|-rwx——||read, write and executable for owner only|
|-rw-rw-rw||read and write for owner, group and all others|
|-rwxr-xr-x||read, write and executable by owner, only read and executable by group and others|
|-rw-r–r-||read and write by owner, read only for group and all others|
To change the permissions, the command chmod is used.
|Options||What it does|
g, o or
|Whose permission you are changing: user, group, other or all|
|+ or>-||Type of change: add permission or subtract permission|
|combination ofr , w or
|which permission you are changing: read, write or execute|
|name of file or directory to change|
|Examples||What it does|
|chmod go-w thisfile||remove write access for group and others for the file ‘thisfile’|
|chmod go+rw file1 file2||add read and write access for group and others for files ‘file1’ and ‘file2’|
|chmod ugo+rwx file1||add read, write and execute for everyone for ‘file1’.|
To change the owner of a file or directory, the command chown is used.
Command: chown username <file or directory>
Example: To change the owner of ‘file1’ and ‘file2’ to the user ‘roger’
chown roger file1 file2
top of page
To change the group of a file or directory, the command ‘chgrp’ is used.
Example: To change the group of ‘file1’ and ‘file2’ to the group ‘mgmt’
chgrp mgmt file1 file2