How to Switch Users Using su Command in Linux
Hey there! 👋 Welcome to this beginner-friendly Linux tutorial from ProgramGuru.org.
In this lesson, we’ll learn how to use the su command in Linux to switch between users on your system. Whether you're managing multiple users or need to perform tasks with elevated privileges, the su command is an essential tool to know.
🔍 What is the su Command?
su stands for “substitute user” or “switch user.” It allows you to temporarily log in as another user without fully logging out or switching terminals.
By default, running su without a username will attempt to switch to the root user.
📌 Syntax
su [options] [username]
👤 Example 1: Switch to the root user
su
You’ll be prompted to enter the root password.
Password:
# (Now you’re operating as root!)
👤 Example 2: Switch to another user
su john
Password:
$ (Now you're logged in as user 'john')
💡 Tip: Confirm the Current User
whoami
john
🔐 What if you get an authentication error?
Make sure the target user has a password set and that you typed it correctly. The root user must also have permission to switch to that account.
⚠️ Important Security Note
- Using
sugives you full control of the target user’s environment. - Be very cautious when switching to
root, as this gives you access to modify or delete critical system files. - Always log out of the root session when done. Just type
exit.
👋 Exiting the su session
exit
$ (Back to your original user)
✅ Recap
Let’s quickly review what we’ve learned:
- Use
suto switch to another user. - Use
su usernameto switch to a specific user. - Type
exitto return to your original session.
And that’s it! 🎉 You now know how to use the su command like a pro.
Stay tuned to ProgramGuru.org for more hands-on Linux tutorials. Happy terminal-ing! 🖥️🐧
