Linux su Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux su Guide
Complete beginner-friendly guide to su on Linux, covering Arch Linux, CachyOS, and other distributions including switching users, becoming root, and user switching.
Table of Contents
Understanding su
What is su?
su (switch user) changes to another user account.
Uses:
- Switch users: Change to different user
- Become root: Switch to root account
- Test permissions: Test as different user
- System maintenance: Run commands as root
Note: Prefer sudo for security, but su is still useful.
su Basics
Become Root
Switch to root:
# Switch to root
su
# Enter root password
# Now you're root
# Exit
exit
Switch to User
Change user:
# Switch to user
su username
# Enter user password
# Now you're that user
# Exit
exit
Switching Users
With Environment
Preserve environment:
# Switch with current environment
su - username
# Or
su -l username
# Full login shell
Without Environment
Minimal environment:
# Switch without changing environment
su username
# Uses current environment
su vs sudo
When to Use su
Use su when:
- Need root shell: Extended root session
- System maintenance: Multiple root commands
- Testing: Test as different user
When to Use sudo
Use sudo when:
- Single command: One command as root
- Security: Better audit trail
- Best practice: Recommended approach
Troubleshooting
Authentication Failed
Check password:
# Verify user exists
id username
# Check if user has password
sudo passwd username
# Try again
su username
Permission Denied
Check access:
# Verify user in wheel group
groups username
# Check /etc/group
grep wheel /etc/group
Summary
This guide covered su usage, user switching, and when to use su vs sudo for Arch Linux, CachyOS, and other distributions.
Next Steps
- sudo Guide - sudo usage
- User and Groups - User management
- su Documentation:
man su
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.