Quick Reference to file sharing

“Permission denied.”

If this error appears when you try to read the file, you don’t have read permission. If the error appears as you try to save the file, you don’t have write permission:

  1. See who owns the file:

        % ls -l filename
  2. Ask the owner for read/write permission.

  3. If the owner isn’t available, ask your system administrator to change the file permissions.

  4. If you have read permission, you can copy the file into your own directory and work on it there; e.g., to copy a file named memo to your own directory:

        % cp memo ~/memo.mine

    Be sure to tell the owner that you made changes to a copy of the file.

Repeated denial to files that you think you should be able to share

  1. See what group can read/write the files:

        % ls -lg filenames
  2. See what groups you are a member of:

       % groups
  3. If you are not a member of the group with permission, ask the file owner to change the group to one you belong to or ask your system administrator to add you to the group.

Can’t create or remove files in a directory

  1. Check directory permissions on the directory:

        % ls -ld directory
  2. Ask the directory’s owner to give you permission:

How to change permissions

  1. Check the file’s permissions, owner, and group:

        % ls -lg
  2. If you are the file’s owner, use chmod. E.g., to add write permission to all for a file named memo:

        % chmod a+w memo

    To add permissions for all users:

        % chmod a+r memo read permission
        % chmod a+w memo write permission
        % chmod a+rw memo read/write

    To add permissions for the group:

        % chmod g+r memo read permission
        % chmod g+w memo write permission
        % chmod g+rw memo read/write

    You can also subtract permissions:

        % chmod g-rw memo

    Or change permissions on all files in a directory:

        % chmod g+rw *

    Or change the group that a file belongs to:

        % chgrp sales memo
  3. Or you can use a three-digit number to indicate what permissions you want for a file; e.g., to give read/write permission to both the file owner (you) and to the group of the file memo, type:

        % chmod 660 memo

    Other possible values for read-only permission:

        400 -r--------
        440 -r--r-----
        444 -r--r--r--

    Read-write:

        600 -rw-------
        660 -rw-rw----
        666 -rw-rw-rw-

    Read-write-execute:

        700 -rwx------
        770 -rwxrwx---
        777 -rwxrwxrwx

    Execute only:

        100  ---x------
        110  ---xx---
        111 ---xx--x

Get WYNTK: UNIX System Admininistrator now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.