Stop losing your shell aliases when you switch users
Environment & Shell Customization (Aliases/Functions/.Bashrc)
Stop losing your shell aliases when you switch users
🧩 The Challenge
You finally spend an hour crafting the perfect alias for a complex log-parsing command, only to sudo su over to root and find your custom environment is completely missing. It drives me up the wall having to remember two different sets of shell tweaks just because I’m running as a different UID.
💡 The Fix
Use a shared alias file that both your regular user and root can source automatically when they log in. You’ll stop duplicating your work and keep your workflow consistent regardless of who you’re acting as.
echo "source /etc/bash_aliases" >> /etc/bash.bashrc && echo "if [ -f /etc/bash_aliases ]; then . /etc/bash_aliases; fi" >> ~/.bashrc
⚙️ Why It Works
Adding the source directive to the global bashrc ensures that any user on the system picks up your shared configuration file. It moves your custom shortcuts out of individual home directories and into a single location where they actually stick.
🚀 Pro-Tip: Store that /etc/bash_aliases file in your dotfiles repo so you can keep your server keys and shell shortcuts synced across your entire fleet.
Linux Tips & Tricks | © ngelinux.com | 10/11/2026
