Setting permission and changing ownership (chmod, chown)
File permissions are determined by who owns the file and the visibility of that file. chown and chmod are the tools we use to manipulate ownership and access. chown is used to change the owner, not the group.
The chmod command stands for “change mode”, and allows changing permissions of files and folders, also known as “modes” in UNIX.
- Used for setting file and directory permissions.
Chmod [OPTION] [Mode][Mode].. Filename
Using Absolute Mode:
chmod [0-7][0-7][0-7] filename/dir
Using Symbolic Mode:
chmod [ugo][+-=][rwx] filename
where + adds specified mode
– removes specified mode
= assigns specified mode for u/g/o
|To change the file and directory permissions recursively|
|Utilize permissions of first argument as reference to set permissions of remaining arguments|
- Chmod -R 755 /home/Data/task1
ls -l /home/Data/task1
New files are created with a default set of permissions. Specifically, a new file’s permissions may be restricted in a specific way by applying a permissions “mask” called the umask. The umask command is used to set this mask, or to show you its current value.
- Stands for user creation mask.
- Sets default permissions for a newly created file and directory.
- Default value is 022.
- The value can be changed.
The chown command stands for “change owner”, and allows changing the owner of a given file or folder, which can be a user and a group.
- Changing ownership for a file.
- Can be done only by the owner and root or administrator.
To change owner of the file:
chown username filename