Commands, Linux

Permission Commands in Linux

permission commands in linux

Linux is a multi-user operating system, so it has security to prevent people from accessing each other’s confidential files.

For effective security, Linux divides authorization into 2 levels.

  1. Ownership 2. Permission

Linux File Ownership : Every Linux system have three types of owner.

  1. User : A user is the one who created the file. By default, whosoever, creates the file becomes the owner of the file. A user can create, delete, or modify the file.
  2. Group : A group can contain multiple users. All the users belonging to a group have same access permission for a file.
  3. Other : Any one who has access to the file other than user and group comes in the category of other. Other has neither created the file nor is a group member.

Users and groups can be locally managed in /etc/psswd or /etc/group.

Permissions : The Unix-like operating systems, such as Linux differ from other computing systems in that they are not only multitasking but also multi-user. What exactly does this mean? It means that more than one user can be operating the computer at the same time.

  1. Read: This permission give you the authority to open and read a file. Read permission on a directory gives you the ability to lists its content.

The r means you can read the file’s contents.

  1. Write: The write permission gives you the authority to modify the contents of a file. The write permission on a directory gives you the authority to add, remove and rename files stored in the directory.

The w means you can write, or modify, the file’s contents.

  1. Execute: In Windows, an executable program usually has an extension “.exe” and which you can easily run. In Unix/Linux, you cannot run a program unless the execute permission is set.

The x means you can “execute” the file. This permission is given only if the file is a program.

  1. – : If any of the “rwx” characters is replaced by a ‘-‘, then that permission has been revoked.

Linux ls command :

ls : List Files and Directories.

ls -l : Long Listing of Files and Directories.

File Permission : On a Linux system, each file and directory is assigned access rights for the owner of the file, the members of a group of related users, and everybody else.

Here is a all file permission details that covers all the common settings.

777 : (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.

755 : (rwxr-xr-x) The file’s owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.

700 : (rwx——) The file’s owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.

666 : (rw-rw-rw-) All users may read and write the file.

644 : (rw-r–r–) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.

600 : (rw——-) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.

Directory Permissions :

777 : (rwxrwxrwx) No restrictions on permissions. Anybody may list files, create new files in the directory and delete files in the directory. Generally not a good setting.

755 : (rwxr-xr-x) The directory owner has full access. All others may list the directory, but cannot create files nor delete them. This setting is common for directories that you wish to share with other users.

700 : (rwx——) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.

Permission numbers are :

  • 0 = — (No Permission),
  • 1 = –x (Execute),
  • 2 = -w- (Write),
  • 3 = -wx (Execute + Write),
  • 4 = r- (Read),
  • 5 = r-x (Read + Execute),
  • 6 = rw- (Read +Write),
  • 7 = rwx (Read + Write +Execute)

Symbolic Mode :

  • + : Adds a permission to a file or directory
  • – : Removes the permission
  • = : Sets the permission and overrides the permissions set earlier.

Permission Commands :

  • chmod : Modify file access rights.
  • su : Temporarily become the superuser.
  • sudo : Temporarily become the superuser.
  • chown : Change file ownership.
  • chgrp : Change a file’s group ownership.

Some Examples :

sudo chmod -R 777 generated/ pub/ var/ – It will give 777 permission to generated,pub & var folders

sudo chmod -R 775 pub/media – It will give 775 permission to pub/media folder.

sudo chown -R root:root pub/ – It will change the owner(user)/group of pub folder.

sudo chgrp root info.php – It will change the Group Ownership.

🙂 Happy Coding. Keep Liking & Sharing 💻

Tagged , ,