Skip to main content

Basic File Permissions in Linux

Basic File Permissions in Linux Basic File Permissions in Linux

Basic File Permissions and Ownership in Linux

File Permissions

File permissions in Linux determine who can read, write, or execute a file. Each file or directory has an associated set of permissions that defines what actions can be performed by the owner, the group, and others.

Permission Types

  • Read (r): Permission to read the contents of the file or directory.
  • Write (w): Permission to modify the contents of the file or directory.
  • Execute (x): Permission to execute the file or traverse the directory.

Permission Representation

Permissions are represented in two ways:

  • Symbolic notation: A string of characters such as rwxr-xr--.
  • Octal notation: A numeric representation like 755.

The symbolic notation consists of ten characters, with the first character indicating the file type (- for regular files, d for directories, etc.), followed by three sets of three characters each representing the permissions for the owner, group, and others.

-rwxr-xr--

In this example:

  • rwx: The owner has read, write, and execute permissions.
  • r-x: The group has read and execute permissions.
  • r--: Others have read-only permissions.

Using chmod to Change Permissions

The chmod command is used to change the permissions of a file or directory. You can use both symbolic and octal notation to set permissions.

Symbolic Notation

To change permissions using symbolic notation:

chmod [permissions] [filename]

Example:

chmod u+x,g-w,o=r file.txt

This command adds execute permission for the owner, removes write permission for the group, and sets read-only permission for others on file.txt.

Octal Notation

To change permissions using octal notation:

chmod [permissions] [filename]

Example:

chmod 755 file.txt

This command sets read, write, and execute permissions for the owner, and read and execute permissions for the group and others on file.txt.

File Ownership

Every file or directory in Linux has an owner and an associated group. The owner is typically the user who created the file, and the group consists of users who share the same permissions.

Using chown to Change Ownership

The chown command is used to change the ownership of a file or directory. You can change both the owner and the group using this command.

Changing Owner

To change the owner of a file:

chown [new_owner] [filename]

Example:

chown alice file.txt

This command changes the owner of file.txt to the user alice.

Changing Group

To change the group of a file:

chown :[new_group] [filename]

Example:

chown :developers file.txt

This command changes the group of file.txt to developers.

Changing Both Owner and Group

To change both the owner and the group of a file:

chown [new_owner]:[new_group] [filename]

Example:

chown alice:developers file.txt

This command changes the owner of file.txt to alice and the group to developers.

Author: Linux Playground

Comments

Popular posts from this blog

Understanding sudo and su: A Comprehensive Guide

Understanding sudo and su: A Comprehensive Guide Understanding sudo and su : A Comprehensive Guide What is sudo ? The sudo (superuser do) command allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. Essentially, sudo grants temporary administrative privileges to perform a specific task. Key Features of sudo : Granular Control: sudo allows system administrators to delegate limited root access to users, specifying exactly which commands they are permitted to run. Auditability: Every use of sudo is logged, providing a clear trail of who used sudo , what commands were executed, and when. Temporary Elevation: sudo grants elevated privileges for the duration of a single command, reducing the risk of accidental system-wide changes. Sec...

Using ping, traceroute, and netstat for Network Diagnostics

Using ping, traceroute, and netstat for Network Diagnostics Using ping, traceroute, and netstat for Network Diagnostics In the complex world of networking, diagnosing and troubleshooting issues is essential for maintaining a healthy and efficient network. Three fundamental tools often used for these purposes are ping , traceroute , and netstat . Each of these utilities offers unique insights into network performance and connectivity. Let's dive into their functionalities, use cases, and how they can be employed effectively. 1. Ping: Checking Connectivity and Latency The ping command is one of the most straightforward and commonly used network diagnostic tools. It tests the reachability of a host on an Internet Protocol (IP) network and measures the round-trip time for messages sent from the source to a destination computer. How It Works: The ping command sends Inte...

Special File Permissions: setuid and setgid

Special File Permissions: setuid and setgid Special File Permissions: setuid and setgid Setuid (Set User ID) The setuid permission is used primarily for executable files. When setuid is applied to a file, it allows users to run the file with the file owner's privileges. This is particularly useful for executing programs that require higher privileges to perform certain operations. How It Works When a user executes a setuid program, the operating system sets the effective user ID of the process to that of the file owner. Example -rwsr-xr-x 1 root root 53232 Jan 14 09:32 /usr/bin/passwd The passwd command, used to change user passwords, typically has the setuid bit set. This allows it to modify system password files which are normally only accessible by the root user. ...