Showing posts with label How to set access permission in a file for specific user in Linux. Show all posts
Showing posts with label How to set access permission in a file for specific user in Linux. Show all posts

Friday 25 December 2015

How to set access permission in a file for specific user in Linux

Files and directories have permission sets for the owner of the file, the group associated with the file, and all other users for the system. However, these permission sets have limitations. For example, different permissions cannot be configured for different users. Thus, Access Control Lists (ACLs) were implemented.

[root@saidrasel]# ll a
-rw-r--r--. 1 root root 0 Dec 25 22:56 a

Above permission means ---file owner is root have permission rw (read,write), group root have permission r (read) and other have permission r (read). Following example showing in details

[root@saidrasel]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
group::r--
other::r--

Now we will set permission in file a for specific user wasi, so for this we need to create a user named wasi

[root@saidrasel]# useradd wasi
[root@saidrasel]# passwd wasi
Changing password for user wasi.
New password: 

Now we will set rwx (read,write and execute) permission for new user wasi

[root@saidrasel]# setfacl -m u:wasi:rwx a
or
[root@saidrasel]# setfacl -m u:wasi:rwx /root/Desktop/a       [for absolute path]

 Now we can check the permission of file a for user wasi

[root@saidrasel]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
user:wasi:rwx
group::r--
mask::rwx
other::r--

[root@saidrasel]#

Thats it..........