20250407 Flashcards
What does the su
command stand for?
Substitute User (or Switch User).
What happens when you run su
without a username?
It switches to the root user (requires the root password).
How do you switch to a different user using su
?
su username
(e.g., su alice
).
How do you execute a single command as another user using su
?
su -c "command" username
(e.g., su -c "ls /root" root
).
What does the -
(dash) option do in su -
?
Starts a full login shell with the target user’s environment.
it switches to the root user and loads the root user’s full environment, as if you had logged in directly as root from a login screen or via SSH.
You can do su - fashouri
the same as ssh fashouri@<same_machine>
A login shell is a session where your user environment is fully set up. That includes:
The user’s PATH settings (so commands work properly)
Environment variables (like HOME, USER, etc.)
Shell configs (~/.bash_profile, ~/.profile, etc.)
When you run su without the dash (-), it switches the user but keeps your original environment, which can cause confusing behavior.
What’s the main difference between su
and sudo
?
su
asks for the other user’s password, sudo
asks for your own.
Where are sudo
permissions managed?
In the /etc/sudoers
file.
Which command is safer in multi-user environments?
sudo
, because it allows fine-grained permission control.
Why might sudo
not work for a command?
You may not be in the sudoers
list or lack permission for that command.