Karan's Programming Notes
Run a command as a different user
Initializing search
    mr-karan/notes
    mr-karan/notes
    • Home
      • CLI
      • Cloud Init
      • EC2 Metadata inside Docker
      • EC2 Pricing
      • View the volume ID in Instance
      • FAQ
      • Snippets
      • Vault
      • Query Snippets
      • Securing server with RBAC
      • CLI
      • Custom Build Output
      • Custom DNS Server
      • Custom subnet
      • CI
      • Decode JSON with proper types
      • Gotchas
      • Inspect HTTP Headers
      • Open File Descriptors
      • Profile Golang Applications
      • Update Golang Version
      • CLI
      • Debug CNI Issues
      • Control Brightness
      • Create a MacOS like screenshot effect
      • Filesystem
      • Git
      • JournalD
      • Networking
      • SystemD
      • cURL
      • Ps
      • Rsync
      • Sed
      • Add Table of Images in Markdown
      • Connect to Pritunl with a custom DNS server
      • API
      • CLI
      • Editor setup
      • Single Node Setup
      • Service List
      • Generate Million Rows
      • Reset WAL Log
      • Open File Descriptors
      • Transform requests to cURL
      • UTC to Local Time
      • Generate Random String
      • Get filename using bash
      • Get number of cores using bash
      • Line count for each file
      • Most used shell commands
      • Run a command as a different user
      • Shellscript Template
      • View a CSV file in Terminal
      • Snippets
      • Snippets

    Run a command as a different user

    Here's an example of running echo but as a consul user:

    sudo -H -u consul bash -c 'echo "I am $USER, with uid $UID"' 
    
    Previous Most used shell commands
    Next Shellscript Template
    Made with ❤️ by Karan.
    Made with Material for MkDocs