0
0
Linux CLIscripting~20 mins

su (switch user) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
su Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this command?
You run the command su -c 'whoami' as a normal user. What will be the output if you enter the root password correctly?
Linux CLI
su -c 'whoami'
Aroot
Bnormal user name
Csu: Authentication failure
Dcommand not found
Attempts:
2 left
💡 Hint
The -c option runs a command as the switched user.
💻 Command Output
intermediate
1:00remaining
What happens if you run su without a username?
You type su and press Enter. What user will you switch to after entering the password?
Linux CLI
su
ASwitches to root user
BSwitches to current user again
CSwitches to nobody user
DShows an error message
Attempts:
2 left
💡 Hint
By default, su switches to the superuser if no username is given.
📝 Syntax
advanced
1:30remaining
Which command correctly switches to user 'alice' and starts a login shell?
Choose the correct su command to switch to user 'alice' with a login shell.
Asu alice --login
Bsu alice -l
Csu - alice
Dsu -l alice
Attempts:
2 left
💡 Hint
The dash - before the username starts a login shell.
🔧 Debug
advanced
2:00remaining
Why does this command fail with 'Authentication failure'?
You run su - bob but get 'Authentication failure' even though you typed the correct password. What could be the reason?
Linux CLI
su - bob
AYou typed the root password instead of bob's password
BUser 'bob' does not have a password set
CThe 'su' command is not installed
DYou are not allowed to run 'su' as a normal user
Attempts:
2 left
💡 Hint
Check if the target user has a valid password.
🚀 Application
expert
2:30remaining
How to run a command as another user without switching shell interactively?
You want to run ls /root as root from your normal user account without entering an interactive shell. Which command achieves this?
Asu -c ls /root
Bsu - root -c 'ls /root'
Csu -c 'ls /root'
Dsu root -c 'ls /root'
Attempts:
2 left
💡 Hint
Use the dash to start a login shell and the -c option to run a command.