Linux : Special permissions to users for file & directories using "setfacl"

 To set special permissions to users for files and directories using the "setfacl" command in Linux, you can follow these steps:

  1. Install the "acl" package if it is not already installed on your system. You can do this using your distribution's package manager, such as apt, yum, or pacman. For example, on Ubuntu or Debian, you can run the following command:


    sudo apt-get install acl
  2. Check the current ACL settings of the file or directory you want to modify by using the "getfacl" command. For example, to check the ACL settings of a file called "example.txt", you can run the following command:

    getfacl example.txt

    This will show you the current permissions and access control entries (ACEs) for the file.

  3. Use the "setfacl" command to add or modify the ACEs for the file or directory. The basic syntax of the "setfacl" command is as follows:

    ruby
    setfacl -m user:<username>:<permissions> <file/directory>

    In this command, you need to replace <username> with the username of the user you want to set permissions for, and <permissions> with the special permissions you want to grant. You can use any of the following special permissions:

    • r: read
    • w: write
    • x: execute
    • d: delete
    • a: append

    For example, to grant the user "krishna" read and write access to the file "example.txt", you can run the following command:

    sql
    setfacl -m user:krishna:rw example.txt

    You can also use the "-R" option to apply the ACEs recursively to all files and directories within a directory. For example, to grant the user "krishna" read and write access to a directory called "mydir" and all its contents, you can run the following command:

    sql
    setfacl -R -m user:krishna:rw mydir
  4. Verify the ACL settings using the "getfacl" command again. For example, to check the ACL settings of the file "example.txt" after setting the ACE for "krishna", you can run the following command:

    getfacl example.txt

    This should show you the updated ACEs for the file.

That's it! You have now set special permissions to users for files and directories using the "setfacl" command in Linux.

Comments

Popular posts from this blog

AWS CLI Script to list all the EC2 Servers in all AWS Accounts in all Regions

Useful Linux Commands