To read about Linux file access permissions please refer our other article here. It will help you understand the Linux files/directories permissions structure.
If you have ownership of a file or directory then you can change access permission of that file for other users. The image given below is showing the permission structure used in
To change ownership of a file or directory in Linux you have to use
- The user for whom you want to change the permission.
- The type of access permission to add, remove or assign.
- The list of files and directories for whom you want to change the permissions separated by spaces.
You can change access permission for the users who are in the following categories:
- the owner of the file (user, u)
- the group that
ownthe file (group, g)
- the other users (others, o)
Access permissions refers to read(r),write(w) and execute(x).
As the root user, you can also change the ownership of a file or directory using the
-rw-r----- 1 jaon users 0 2006-06-23 16:08 checklist.txt
-rw-r--r-- 1 jaon users 53279 2006-06-21 13:16 gnome_quick.xml
-rw-rw---- 1 jaon users 0 2006-06-23 16:08 index.htm
-rw-r--r-- 1 jaon users 70733 2006-06-21 09:35 kde-start.xml
drwxr-xr-x 2 tux users 48 2006-06-23 16:09 local
In the above example, user
How to modify access permissions for your files?
- If you want to allow the
usersgroup write access to
kde-start.xml then use following command:
chmod g+w kde-start.xml
- To allow the
usersgroup and other users write access to
kde-start.xml use following command:
chmod go+w kde-start.xml
- To remove write access for all users use this command as follows:
chmod -w kde-start.xml
- If you don’t want to
allow usersgroup and others to change into the
localdirectory, use following command.
chmod go-x local
- To allow write access to other users to two files at same time, use following command:
chmod o+w kde_quick.xml gnome_quick.xml
Let’s see the commands used to change ownership of files and directories.
The Root user can change ownership for other user’s data.
chown kristy kde_quick.xml
In above example, we have changed ownership for file kde_quick.xml
To check if the ownership changed or not, lets list the file using ls -l
ls -l kde_quick.xml
-rw-r--r-- 1 kristy users 47896 2006-06-21 09:46 kde_quick.xml
It is done!