In linux assigned permission for user and file both using permission assigned for user which permission for user if we assigned read permission on file other user can only read then same as write or execute also. File ownership is an important component of linux that provides a secure method for storing files.
Owner permissions − The owner’s permissions determine what actions the owner of the file can perform on the file.
Group permissions − The group’s permissions determine what actions a user, who is a member of the group that a file belongs to, can perform on the file.
Other (world) permissions − The permissions for others indicate what action all other users can perform on the file.
How to list file or directory permission
Using the ls -l command list the file permission
# ls -l /home/amrood -rwxr-xr-- 1 amrood users 1024 Nov 2 00:10 myfile drwxr-xr--- 1 amrood users 1024 Nov 2 00:10 mydir
Here the
The permission is assign sum of the read+weite+execute gor the single user same as the group and same as the all
Privilege | Definition |
read (r) | reading, opening, viewing, and copying the file is allowed |
write (w) | writing, changing, deleting, and saving the file is allowed |
execute (x) | executing and invoking the file is allowed. This is required for directories to allow searching and access. |
File permission assign type
Type 1: How to Change Permissions in Alphabetic
The chmod command is use for the change the permission of the user or directory in + is add permission – is remove the permission. consider as example
# chmod [PARMISSION] [FILE OR DIRECTORY NAME] # chmod +rwx xyz # chmod -rws xyz # chmod +x [FILE OR DIRECTORY NAME] executable permissions # chmod -wx filename write and executable permissions
The command for changing directory permissions for group owners is similar, but add a “g” for group or “o” for users
# chmod g+w [FILE NAME] # chmod g-wx [FILE NAME] # chmod o+w [FILE NAME] # chmod o-rwx [DIRECOTORY NAME] # chmod ugo+rwx foldername [give read, write, and execute to everyone] # chmod a=r foldername [give only read permission for everyone]
Type 2:How to Change Permissions in Numeric Code in Linux
You may need to know how to change permissions in numeric code in Linux, so to do this you use numbers instead of “r”, “w”, or “x”.
r = read permission Numeric no= 4 w = write permission Numeric no= 2 x = execute permission Numeric no= 1 – = no permission Numeric no= 0
Permission numbers are:
- 0 = —
- 1 = –x
- 2 = -w-
- 3 = -wx
- 4 = r-
- 5 = r-x
- 6 = rw-
- 7 = rwx
# chmod 777 [DIRECTORY NAME] Read, write, and execute permissions for everyone # chmod 777 it # chmod 700 it give read, write, and execute permissions for the user only # chmod 327 it will give write and execute (3) permission for the user, w (2) for the group, and read, write, and execute for the users
How to Change Ownership in Linux
These commands will give ownership to someone, but all sub files and directories still belong to the original owner. You can also combine the group and ownership command by using.
# chown -R name:filename /home/name/directory