Day 6 Task: File Permissions and Access Control Lists

Day 6 Task: File Permissions and Access Control Lists

Create a simple file and do ls -ltr to see the details of the files

In the Linux/Unix operating system, there are many ways available to create files.

Using the touch command:

The touch command is used to create file/files without any content and update the access date or modification date of a file or directory in the Linux system. This is the simplest way to create a file in Linux/Unix using a terminal.

Syntax: $touch filename

Using the cat command

The cat (concatenate) command is used to create, view, and concatenate files in the Linux operating system. The touch command is also used to create files in the Linux system without content whereas the cat creates files with some content. The cat command reads the content of a file and prompts it.

Syntax: $cat >filename

Using Vi and Vim editor:

Its main function is to edit files. It is commonly used by programmers to edit the textual content of any file on the vi text editor. Major operations that can be done using it are as follows:

To save and exit from the vi-text editor, press the Escape key and then type:wq and hit enter.

Using the nano command:

It may/may not be found in all distributions of LINUX. We can create as well as edit files. To exit nano Text Editor press ctrl + x.

Syntax: $nano filename

Here we will create file using touch

Each of the three permissions is assigned to three defined categories of users. The categories are:

user/owner(u) - The owner of the file.

group(g) - The group that owns the file.

others(o) - All users with access to the system.

chown:

chown command is used to change a file's ownership, directory, or symbolic link for a user or group. The chown stands for change owner. In Linux, each file is associated with a corresponding owner or group.

Syntax: chown owner_name filename

  • chgrp :

    Linux chgrp command is used to change the group ownership of a file or directory. In the Linux file system, each file is related to the corresponding owner and group and has read, write, and execute permission.

  • chmod :

    Linux chmod command is used to change the access permissions of files and directories. It stands for change mode. It can not change the permission of symbolic links. It even, ignores the symbolic links that come across recursive directory traversal.

    In the Linux file system, each file is associated with a particular owner and has permission access for different users. The user classes may be:

  • u=user/owner

  • g=group member

  • o=others

    Syntax: chmod permissions filename

  • permissions:

    r=read

    w=write

    x=execute

  • Access modes:

    r =4 - To display the content(file)

    To list the content(directory)

    w=2 - To modify(file)

    To create or remove file in a directory(directory)

    x=1 - To execute the file

    To enter into the directory

    Another method:

  • If we want the user to get full permission: u=rwx

  • If only one permission we want to provide: u+r

  • If remove specific permission: u-r

  1. Read about ACL and try out the commands getfacl and setfacl

    ACL(Access Control List)-

    This command applies permissions to any particular file and folders to be read, write and executed by particular users or groups.

    syntax:

    setfacl -m u:username: permissions file/folder

    setfacl -m g:username: permissions file/folder

    Example:

    setfacl -m u:ram:rwx file.txt

    getfacl file.txt

    setfacl -m g:admin:rw file.txt

    getfacl file.txt

    Happy Learning!!!!!