Linux view folder permissions

Ubuntu Documentation

Understanding and Using File Permissions

In Linux and Unix, everything is a file. Directories are files, files are files and devices are files. Devices are usually referred to as a node; however, they are still files. All of the files on a system have permissions that allow or prevent others from viewing, modifying or executing. If the file is of type Directory then it restricts different actions than files and device nodes. The super user «root» has the ability to access any file on the system. Each file has access restrictions with permissions, user restrictions with owner/group association. Permissions are referred to as bits.

To change or edit files that are owned by root, sudo must be used — please see RootSudo for details.

If the owner read & execute bit are on, then the permissions are:

There are three types of access restrictions:

Permission

Action

chmod option

There are also three types of user restrictions:

User

ls output

Note: The restriction type scope is not inheritable: the file owner will be unaffected by restrictions set for his group or everybody else.

Folder/Directory Permissions

Directories have directory permissions. The directory permissions restrict different actions than with files or device nodes.

Permission

Action

chmod option

(view contents, i.e. ls command)

(create or remove files from dir)

(cd into directory)

read restricts or allows viewing the directories contents, i.e. ls command

write restricts or allows creating new files or deleting files in the directory. (Caution: write access for a directory allows deleting of files in the directory even if the user does not have write permissions for the file!)

execute restricts or allows changing into the directory, i.e. cd command

» height=»16″ src=»/moin_static198/light/img/icon_cool.png» title=»Info » width=»16″/> Folders (directories) must have ‘execute’ permissions set (x or 1), or folders (directories) will NOT FUNCTION as folders (directories) and WILL DISAPPEAR from view in the file browser (Nautilus).

Permissions in Action

Using the example above we have the file «/etc/hosts» which is owned by the user root and belongs to the root group.

What are the permissions from the above /etc/hosts ls output?

Changing Permissions

The command to use when modifying permissions is chmod. There are two ways to modify permissions, with numbers or with letters. Using letters is easier to understand for most people. When modifying permissions be careful not to create security problems. Some files are configured to have very restrictive permissions to prevent unauthorized access. For example, the /etc/shadow file (file that stores all local user passwords) does not have permissions for regular users to read or otherwise access.

Источник

How to View File and Folder Permissions in Ubuntu Linux Command Line

To View Permissions

To list permission of each file in a directory, in this example /var :

To list file permissions for filename.txt :

Читайте также:  Отключение файла подкачки linux

To list directory permissions for /var :

To list permissions files in a folder including hidden files.

To list file permissions in a folder with human readable file size:

Changing Permissions

Single File or Folder

To change permissions of file to 644 for example:

To change permissions of directory to 755 for example:

All Files

To change all files recursively to 644 .

All Folders

To change all directories recursively to 755 .

Changing Owner/Group

Change Owner/Group of a File

Change Owner/Group of All Files/Directories

To change the owner and group of all files and directories recursively within a directory.

To change the owner and group of a directory, and all the files and directories within it recursively.

Permission Groups

Each file and directory has three user based permission groups:

  • owner – The Owner permissions apply only the owner of the file or directory, they will not impact the actions of other users.
  • group – The Group permissions apply only to the group that has been assigned to the file or directory, they will not effect the actions of other users.
  • all users – The All Users permissions apply to all other users on the system, this is the permission group that you want to watch the most.

Permission Types

Each file or directory has three basic permission types:

  • read – The Read permission refers to a user’s capability to read the contents of the file.
  • write – The Write permissions refer to a user’s capability to write or modify a file or directory.
  • execute – The Execute permission affects a user’s capability to execute a file or view the contents of a directory.

Numeric Meanings

Numeric Readable Explanation
0 No access.
1 –x Execute access.
2 -w- Write access.
3 -wx Write and execute access.
4 r– Read access.
5 r-x Read and execute access.
6 rw- Read and write access.
7 rwx Read, write and execute access.

Common File Permissions

Setting Numerical Owner Group Others
-rw——- 600 Read/Write
-rw-r—– 640 Read/Write Read
-rw-r–r– 644 Read/Write Read Read
-rw-rw-r– 664 Read/Write Read/Write Read
-rwx—— 700 Read/Write/Execute
-rwxr-xr-x 755 Read/Write/Execute Read/Execute Read/Execute
-rwx–x–x 711 Read/Write/Execute Execute Execute
-rw-rw-rw- 666 Read/Write Read/Write Read/Write
-rwxrwxrwx 777 Read/Write/Execute Read/Write/Execute Read/Write/Execute

Common Directory Permissions

Setting Numerical Owner Group Others
drwx—— (700) Read/Write/Execute
drwxr—– (750) Read/Write/Execute Read
drwxr-xr-x (755) Read/Write/Execute Read/Execute Read/Execute
drwxrwx— (770) Read/Write/Execute Read/Write/Execute
drwxrwxr-x (775) Read/Write/Execute Read/Write/Execute Read/Execute

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.

4 replies

Leave a reply

Cant I just grant root to a user and limit there ability to do anythi9ng administrative?

bassicly I want my second user to be able to access anything and everything but not be able to make system changes on need to remember my password.

Hello,
I am on Ubuntu 20.04, gnome, newcomer from 30 years using Windows.
I setup a backup of my own folders using rsync, Cron scheduler.

I can see the folders and files that were created on the external SD card using terminal command line.
But, gnome file manager shows me an empty folder only. Also tried PCManFM, same thing, can’t see the resulting backup.

Maybe you can tell me what to do…
Cheers
Alex

Hi.
I’m really struggling here.
All my files have 777 permissions. I cannot figure out how to view/open the files.

Everytime I try to open them in windows it will say there is no program to view.
In Ubuntu terminal I can’t seem to view it in any way.
Any ideas?
Thank you
Dave

Who is the owner and group of the files and parent directory? You can find out with:

ls -la /path/to/directory

You may have to change the ownership of the files and directory to your own username and group.

sudo chown -R username:groupname /path/to/directory*

Источник

Linux File Permission Tutorial: How to Check and Change Permissions

Home » SysAdmin » Linux File Permission Tutorial: How to Check and Change Permissions

Linux, like other Unix-like operating systems, allows multiple users to work on the same server simultaneously without disrupting each other.

Individuals sharing access to files pose a risk exposing classified information or even data loss if other users access their files or directories. To address this, Unix added the file permission feature to specify how much power each user has over a given file or directory.

In this tutorial, you will learn how to view and change file permissions in Linux.

How to View Check Permissions in Linux

To start with file permissions, you have to find the current Linux permission settings. There are two options to choose from, depending on your personal preference: checking through the graphical interface or using the command.

Check Permissions using GUI

Finding the file (directory) permission via the graphical user interface is simple.

1. Locate the file you want to examine, right-click on the icon, and select Properties.

2. This opens a new window initially showing Basic information about the file.
Navigate to the second tab in the window, labeled Permissions.

3. There, you’ll see that the permission for each file differs according to three categories:

  • Owner (the user who created the file/directory)
  • Group (to which the owner belongs to)
  • Others (all other users)

For each file, the owner can grant or restrict access to users according to the categories they fall in.

In our example, the owner of the file test.txt has access to “Read and write”, while other members of its group, as well as all other users, have “Read-only” access. Therefore, they can only open the file, but cannot make any modifications.

To alter the file configuration, the user can open the drop-down menu for each category and select the desired permission.

Additionally, you can make the file executable, allowing it to run as a program, by checking the Execute box.

Check Permissions in Command-Line with Ls Command

If you prefer using the command line, you can easily find a file’s permission settings with the ls command, used to list information about files/directories. You can also add the –l option to the command to see the information in the long list format.
To check the permission configuration of a file, use the command:

For instance, the command for the previously mentioned file would be:

As seen in the image above, the output provides the following information:

  • file permission
  • the owner (creator) of the file
  • the group to which that owner belongs to
  • the date of creation.

It shows the permission settings, grouped in a string of characters (-, r, w, x) classified into four sections:

  1. File type. There are three possibilities for the type. It can either be a regular file (), a directory (d) or a link (i).
  2. File permission of the user (owner)
  3. File permission of the owner’s group
  4. File permission of other users

The characters r, w, and x stand for read, write, and execute.
The categories can have all three privileges, just specific ones, or none at all (represented by , for denied).

Users that have reading permission can see the content of a file (or files in a directory). However, they cannot modify it (nor add/remove files in a directory). On the other hand, those who have writing privileges can edit (add and remove) files. Finally, being able to execute means the user can run the file. This option is mainly used for running scripts.

In the previous example, the output showed that test.txt is a regular file with read and write permission assigned to the owner, but gives read-only access to the group and others.

Using Chmod Command to Change File Permissions

As all Linux users, you will at some point need to modify the permission settings of a file/directory. The command that executes such tasks is the chmod command.

The basic syntax is:

There are two ways to define permission:

  1. using symbols (alphanumerical characters)
  2. using the octal notation method

Define File Permission with Symbolic Mode

To specify permission settings using alphanumerical characters, you’ll need to define accessibility for the user/owner (u), group (g), and others (o).

Type the initial letter for each class, followed by the equal sign (=) and the first letter of the read (r), write (w) and/or execute (x) privileges.

To set a file, so it is public for reading, writing, and executing, the command is:

To set permission as in the previously mentioned test.txt to be:
• read and write for the user
• read for the members of the group
• read for other users

Use the following command:

Note: There is no space between the categories; we only use commas to separate them.

Another way to specify permission is by using the octal/numeric format. This option is faster, as it requires less typing, although it is not as straightforward as the previous method.

Instead of letters, the octal format represents privileges with numbers:

  • r(ead) has the value of 4
  • w(rite) has the value of 2
  • (e)x(ecute) has the value of 1
  • no permission has the value of 0

The privileges are summed up and depicted by one number. Therefore, the possibilities are:

  • 7 – for read, write, and execute permission
  • 6 – for read and write privileges
  • 5 – for read and execute privileges
  • 4 – for read privileges

As you have to define permission for each category (user, group, owner), the command will include three (3) numbers (each representing the summation of privileges).

For instance, let’s look at the test.txt file that we symbolically configured with the chmod u=rw,g=r,o=r test.txt command.

The same permission settings can be defined using the octal format with the command:

Define File Permission in Octal/Numeric Mode

Note: If you need a more in-depth guide on how to use Chmod In Linux to change file permissions recursively, read our Chmod Recursive guide.

Changing User File and Group Ownership

Aside from changing file permissions, you may come across a situation that requires changing the user file ownership or even group ownership.

Performing either of these tasks requires you first need to switch to superuser privileges. Use one of the options outlined in the previous passage.

To change the file ownership use the chown command:

Instead of [user_name] type in the name of the user who will be the new owner of the file.

To change the group ownership type in the following command:

Instead of [group_name] type in the name of the group that will be the new owner of the file.

Learning how to check and change permissions of Linux files and directories are basic commands all users should master. To change file’s group permissions, you might find helpful our article on how to use the chgrp command.

No matter whether you prefer using the GUI or command-line, this article should help you better understand how to use file permissions.

Источник

Читайте также:  Termserv dll windows 10
Оцените статью