LogoLogo
  • Welcome
  • Explorers
    • Aptos Explorer
    • Cosmos Explorer
  • Blockchains
    • Aptos
      • Run a Validator and VFN
        • Operator
        • Node Requirements
        • Deploy Nodes
          • Using Source Code
        • Connect Nodes
          • Connect to a Network
          • Staking Pool Operations
          • Delegation Pool Operations
          • Staking Pool Voter
        • Verify Nodes
          • Node Health
          • Validator Leaderboard
        • Modify Nodes
          • Upgrade Nodes
          • Shutdown Nodes
      • Run a Public Fullnode
        • PFN Requirements
        • Deploy a PFN
          • Deploy a PFN using Source Code
        • Verify a PFN
        • Modify a PFN
          • Customize PFN Networks
          • Generate a PFN Identity
          • Upgrade your PFN
          • Run a PFN from Source Code
      • Bootstrap a Node with historical data
        • Bootstrap from a Backup
        • Bootstrap from a Snapshot
      • Configure a Node
        • State Synchronization
        • Data Pruning
        • Telemetry
        • Locating Node Files
          • Files For Mainnet
          • Files For Testnet
          • Files For Devnet
      • Monitor your Nodes
        • Important Node Metrics
        • Node Health Checker
        • Node Health Checker FAQ
        • Node Inspection Service
      • Building Aptos From Source
      • Aptos Networks
    • Berachain V2
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • gRPC Endpoint
      • Live Peers
      • Forest Staking Peer
      • Performance Optimizer Script
      • Discord & TG Alert System
      • RPC Load Balancer Setup
    • Casper
      • Explorer
    • Haqq
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Mantra
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Ika
    • Story Protocol
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • EVM Endpoint
      • Websocket
      • WSS
      • Discord & TG Alert System
      • RPC Load Balancer
      • Performance Optimizer Script
      • Live Peers
      • Forest Staking Peer
    • Supra
      • Explorer
      • Oracle data
    • Showdown
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Soarchain
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Zenrock
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Zetachain
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Airchains
      • Node Snapshot
      • Explorer
  • Gunzilla - Off The Grid
    • Vision and Foundation
    • Gunzilla Hacker Dashboard
      • Key Features of the Hackers Dashboard
        • Wallet Integration and Testnet Access
        • License System with Rarity Tiers
        • Decoding Stats and Hash Power Tracking
        • Marketplace for Trading Licenses and Assets
        • Scanner Tool for Blockchain Transparency
        • Social Media Integration and Community Engagement
      • Mastering the Hackers Dashboard
      • Benefits of the Hackers Dashboard
    • Gunzilla Token Page
  • Forest Esports Team
    • Forest Hexers
  • Crypto Tools & Analytics
    • Top 10 Crypto Exchanges
      • Binance
      • Coinbase
      • Kraken
      • Bybit
      • OKX
      • KuCoin
      • Bitfinex
      • Gemini
      • Crypto.com
      • Bitstamp
    • Top 10 Wallets
      • Ledger Nano X
      • Trezor Model T
      • Exodus
      • Coinbase Wallet
      • Trust Wallet
      • MetaMask
      • Crypto.com DeFi Wallet
      • ZenGo
      • Atomic Wallet
      • SafePal
  • Top 10 Crypto Data Platforms
    • CoinMarketCap
    • CoinGecko
    • CryptoCompare
    • CoinCodex
    • Live Coin Watch
    • CoinCheckup
    • Messari
    • CoinPaprika
    • Arkham Intelligence
  • DeFi Analytics and Tracking
    • DefiLlama
    • Dune Analytics
    • DeBank
    • Zapper
    • Token Terminal
    • DeepDAO
    • Revert Finance
    • L2BEAT
  • API's
    • What are APIs?
    • How APIs Work
    • Types of APIs
    • Real-World API Use Cases
    • Benefits of Using API's
    • Challenges and Considerations of using API's
  • Node Security
    • Physical Security
    • Network Security
    • System and Software Security
    • Access Control
    • Data Security
    • Monitoring and Logging
    • Backup and Disaster Recovery
    • Best Practices for Validator Nodes
    • Cloud Security
    • Incident Response and Recovery
  • Linux Bash
    • Bash 101
      • Getting Started with Bash
      • Navigating the File System
      • File Management Basics
      • Viewing and Editing Files
      • Managing Permissions
      • Working with Processes
      • Using Pipes and Redirection
      • Bash Scripting Basics
      • Essential Networking Commands
      • Installing Software with Package Managers
    • Advanced Linux for Validator Nodes
      • Advanced Bash Scripting for Node Automation and Maintenance
      • Monitoring and Logging Essentials
      • Networking and Security Best Practices
      • Backup and Disaster Recovery
  • Staking 101
    • Understand What Staking Is and How It Works
    • Choose a Blockchain Network to Stake On
    • Set Up a Compatible Wallet for Staking
    • Purchase or Transfer Funds for Staking
    • Choose a Staking Pool
    • Connect Your Wallet to a Staking Platform
    • Confirm and Stake Your Funds
    • Monitor Staking Rewards and Performance
    • Withdraw or Re-Stake Rewards
  • Optimizing Your Infrastructure Choices
    • Infrastructure Comparison: VPS vs. Bare Metal
Powered by GitBook
On this page

Was this helpful?

  1. Linux Bash
  2. Bash 101

Managing Permissions

File permissions and ownership in Linux play a crucial role in system security and access control, determining who can read, modify, or execute files and directories. Understanding permissions is essential for maintaining a secure and organized environment, especially on multi-user systems where certain files need to be protected from unauthorized access.

Linux permissions are divided into three main categories for each file and directory:

  • r (read): Allows a user to view the contents of a file or list the contents of a directory.

  • w (write): Grants permission to modify or delete a file. For directories, it allows the creation, renaming, and deletion of files within that directory.

  • x (execute): Lets a user run a file as a program. For directories, it allows access to files within the directory if the user also has read permission.

Permissions are assigned to three groups:

  • Owner: The user who owns the file.

  • Group: A group of users who have specific access to the file.

  • Others: All other users on the system who are not the owner or in the group.

Permissions are represented in a symbolic format (rwxr-xr-x) or numerically (like 755), and they can be modified using commands like chmod and chown.


1. chmod – Change File Permissions

The chmod (change mode) command modifies the read, write, and execute permissions of files and directories. You can use either symbolic or numeric representation to set permissions.

  • Symbolic Format:

    • r for read, w for write, and x for execute.

    • Permissions are applied for the user (u), group (g), and others (o).

    Example:

    bashCopy code$ chmod u+rwx,go+rx file.txt

    This command gives the owner (u) read, write, and execute permissions, while granting the group (g) and others (o) read and execute permissions on file.txt.

  • Numeric Format:

    • The numeric format assigns permissions using three digits. Each digit represents the permission level for the user, group, and others, respectively.

    • r = 4, w = 2, and x = 1. To combine permissions, add these values together.

    Example:

    bashCopy code$ chmod 755 file.txt

    Here, 755 grants the owner full permissions (7 = 4+2+1), and the group and others get read and execute permissions (5 = 4+1).

  • Common Permission Settings:

    • 755 – Owner has full permissions; group and others have read and execute permissions (common for directories).

    • 644 – Owner can read and write; group and others can only read (common for files).


2. chown – Change File Ownership

The chown (change owner) command allows you to modify the ownership of files and directories. Ownership is typically divided between a user (owner) and a group.

  • Basic Usage:

    bashCopy code$ chown username filename

    This command changes the owner of filename to username.

  • Changing Owner and Group:

    bashCopy code$ chown username:groupname filename

    This command changes the owner to username and the group to groupname for filename. This is useful when you want a specific group of users to have shared access to a file.

  • Changing Ownership for Directories:

    • Use the -R (recursive) option to apply changes to all files and subdirectories within a directory:

      bashCopy code$ chown -R username:groupname /path/to/directory
    • This command is useful when transferring ownership of multiple files or directories, as it ensures that all contained items inherit the new ownership.

Why Use chown? Changing ownership is essential in multi-user environments, where each user or group requires specific access. For instance, if several users are part of a developers group and need to edit files in a shared directory, you could set the group ownership to developers, allowing them the required permissions without affecting other users.


Combining chmod and chown for Secure Access

Using chmod and chown together ensures secure and organized access across files and directories:

  1. Set Initial Permissions: Use chmod to set the appropriate permissions for the owner, group, and others.

  2. Assign Ownership: Use chown to assign ownership to the correct user or group, ensuring the right people have access.

  3. Apply Recursively for Consistency: If working with directories, use the recursive option (-R) to apply changes to all subdirectories and files.

Example Scenario: Suppose you have a directory /project that contains files shared among team members in the devteam group. You could:

  1. Set the group ownership to devteam:

    bashCopy code$ chown -R username:devteam /project
  2. Allow read, write, and execute permissions for the owner, and read and execute permissions for the group:

    bashCopy code$ chmod -R 750 /project

This setup grants the owner full control, allows the team (devteam) to access and execute files, and blocks all others from accessing the directory.


Permission Representation Summary

When listing files with ls -l, permissions are shown in symbolic form, such as:

diffCopy code-rwxr-xr--

Here’s a breakdown:

  • First Character: - indicates a regular file, d indicates a directory, and l indicates a symbolic link.

  • User Permissions: The next three characters (rwx) represent the owner’s permissions (read, write, execute).

  • Group Permissions: The following three characters (r-x) represent group permissions.

  • Other Permissions: The last three characters (r--) represent permissions for all other users.


PreviousViewing and Editing FilesNextWorking with Processes

Last updated 6 months ago

Was this helpful?

Page cover image