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

Configuring Network Interfaces

Configuring Network Interfaces Configuring Network Interfaces Configuring network interfaces is a critical task for both system administrators and enthusiasts looking to optimize the performance and security of their networked devices. Network interfaces are the gateways that connect a device to a network, whether it's a local area network (LAN), wide area network (WAN), or the internet. This article will delve into the essential steps and considerations for configuring network interfaces across various operating systems and environments. Understanding Network Interfaces A network interface can be either physical, like an Ethernet port, or virtual, like those used in virtual machines or containers. Each network interface has a unique Media Access Control (MAC) address and can be assigned an IP address. Proper configuration ensures efficient data transmission, network security, and optimal performance. Steps to Config...

ACLs: Access Control Lists

ACLs: Access Control Lists ACLs: Access Control Lists Introduction Access Control Lists (ACLs) are a fundamental aspect of network security and management, crucial for ensuring that only authorized users have access to specific resources within a network. As networks become more complex, ACLs serve as a vital tool for administrators to control the flow of traffic and enforce security policies. What Are ACLs? An Access Control List is a set of rules that dictate what kind of traffic is allowed to enter or exit a network. These rules are applied to network devices such as routers and switches to control the movement of data packets. Each rule within an ACL specifies whether to permit or deny traffic based on criteria such as source and destination IP addresses, protocol types, and port numbers. Types of ACLs Standard ACLs These ACLs filter traffic based only on the source IP address. They are simpler bu...

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...