Linux runuser Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux runuser Guide
Complete beginner-friendly guide to runuser on Linux, covering Arch Linux, CachyOS, and other distributions including running commands as different users, user switching, and privilege management.
Table of Contents
runuser Basics
Run as User
Basic usage:
# Run command as user
runuser -l username -c 'command'
# -l = login shell
# -c = command
Simple Usage
Basic command:
# Run as user
runuser -u username command
# -u = user (runs command as user)
Running as User
Execute Command
Run command:
# Execute command
runuser -u username -c 'ls -la'
# Runs ls as specified user
Login Shell
With login shell:
# Login shell
runuser -l username -c 'echo $HOME'
# -l = login (full login environment)
User Switching
Switch User
Change user:
# Switch to user
runuser -l username
# Opens shell as user
Without Login
No login shell:
# Without login
runuser -u username
# Runs shell without full login
Environment
Preserve Environment
Keep environment:
# Preserve environment
runuser -u username -c 'env'
# Shows user's environment
Custom Environment
Set environment:
# Custom environment
runuser -u username -c 'HOME=/custom command'
# Sets custom HOME
Troubleshooting
runuser Not Found
Check installation:
# runuser is part of util-linux
# Usually pre-installed
# Check runuser
which runuser
Summary
This guide covered runuser usage, user switching, and privilege management for Arch Linux, CachyOS, and other distributions.
Next Steps
- su Guide - Switch user
- sudo Guide - Execute as another user
- User and Groups - User management
- runuser Documentation:
man runuser
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.