Bird
Raised Fist0
Linux CLIscripting~5 mins

sudo for elevated privileges in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What does the sudo command do in Linux?

sudo lets a user run commands with the security privileges of another user, usually the superuser (root). It is used to perform tasks that require higher permissions.

Click to reveal answer
beginner
Why should you be careful when using sudo?

Using sudo gives you powerful access that can change or damage system files. Mistakes can cause system problems or security risks.

Click to reveal answer
beginner
How do you run a command with sudo?

Simply type sudo before the command. For example, sudo apt update runs the update command with elevated privileges.

Click to reveal answer
beginner
What happens if you enter the wrong password when using sudo?

The command will not run. sudo asks for your user password to confirm your identity. If wrong, it denies access.

Click to reveal answer
intermediate
What is the difference between su and sudo?

su switches the user to another user account (often root) and requires that user's password. sudo runs a single command with elevated rights using your own password.

Click to reveal answer
What is the main purpose of the sudo command?
AChange file permissions
BSwitch to a different user account permanently
CList files in a directory
DRun commands with higher privileges
Which password does sudo ask for when you run a command?
ARoot user password
BNo password is required
CYour own user password
DThe password of the last logged-in user
What happens if you enter the wrong password when using sudo?
AAccess is denied and the command does not run
BYou get logged out
CThe command runs anyway
DThe system restarts
Which command runs a single command with elevated privileges without switching users?
Asu
Bsudo
Cchmod
Dpasswd
Why is it important to use sudo carefully?
AIt can cause system damage if misused
BIt disables the internet
CIt deletes your user account
DIt can slow down your computer
Explain what sudo does and why it is used in Linux.
Think about how you get permission to do special tasks on your computer.
You got /4 concepts.
    Describe the difference between sudo and su commands.
    One lets you do one thing as admin, the other changes who you are.
    You got /4 concepts.

      Practice

      (1/5)
      1. What is the main purpose of using sudo in Linux?
      easy
      A. To create a new user account
      B. To switch to another user account permanently
      C. To list files in a directory
      D. To run commands with higher privileges than a normal user

      Solution

      1. Step 1: Understand what sudo does

        sudo allows a user to run commands with elevated privileges, usually root access.
      2. Step 2: Compare options with sudo purpose

        Only To run commands with higher privileges than a normal user describes running commands with higher privileges, which matches sudo's main use.
      3. Final Answer:

        To run commands with higher privileges than a normal user -> Option D
      4. Quick Check:

        sudo = elevated privileges [OK]
      Hint: sudo means run as superuser or admin [OK]
      Common Mistakes:
      • Confusing sudo with user switching commands
      • Thinking sudo creates users
      • Assuming sudo lists files
      2. Which of the following is the correct syntax to run the command apt update with elevated privileges?
      easy
      A. sudo apt update
      B. apt sudo update
      C. sudo -u apt update
      D. apt update sudo

      Solution

      1. Step 1: Recall the correct sudo syntax

        The correct syntax is sudo [command], so sudo apt update is valid.
      2. Step 2: Check each option

        Options A, B, and D place sudo incorrectly or misuse flags.
      3. Final Answer:

        sudo apt update -> Option A
      4. Quick Check:

        sudo before command = correct syntax [OK]
      Hint: Put sudo before the command to elevate it [OK]
      Common Mistakes:
      • Placing sudo after the command
      • Using sudo with wrong flags
      • Mixing sudo with user flags incorrectly
      3. What will be the output of the command sudo whoami if run by a normal user?
      medium
      A. root
      B. sudo
      C. normal user name
      D. Permission denied

      Solution

      1. Step 1: Understand what whoami does

        whoami prints the current user's name.
      2. Step 2: Effect of sudo on whoami

        Running sudo whoami runs the command as root, so it prints root.
      3. Final Answer:

        root -> Option A
      4. Quick Check:

        sudo changes user to root for command [OK]
      Hint: sudo runs command as root user [OK]
      Common Mistakes:
      • Expecting normal username output
      • Thinking sudo prints 'sudo'
      • Assuming permission denied without sudo
      4. You try to run sudo apt-get update but get the error: sudo: command not found. What is the most likely cause?
      medium
      A. You typed the command incorrectly
      B. You are not logged in as root
      C. The sudo package is not installed or not in PATH
      D. You need to use su instead of sudo

      Solution

      1. Step 1: Analyze the error message

        sudo: command not found means the system cannot find the sudo program.
      2. Step 2: Identify common reasons

        This usually happens if sudo is not installed or its location is missing from the PATH environment variable.
      3. Final Answer:

        The sudo package is not installed or not in PATH -> Option C
      4. Quick Check:

        command not found = missing sudo or PATH [OK]
      Hint: command not found means sudo missing or PATH wrong [OK]
      Common Mistakes:
      • Assuming user login affects sudo command presence
      • Thinking command typo causes 'command not found'
      • Confusing su and sudo usage errors
      5. You want to run a script backup.sh that requires root permissions. Which command correctly runs it with sudo and ensures the script's environment variables are preserved?
      hard
      A. sudo ./backup.sh
      B. sudo -E ./backup.sh
      C. sudo -u root ./backup.sh
      D. sudo --preserve-env=ALL ./backup.sh

      Solution

      1. Step 1: Understand environment preservation with sudo

        By default, sudo resets environment variables for security. The -E flag preserves the user's environment.
      2. Step 2: Evaluate options for preserving environment

        sudo -E ./backup.sh uses -E which preserves environment variables. sudo --preserve-env=ALL ./backup.sh uses a longer form but --preserve-env=ALL is less common and may not be supported everywhere.
      3. Final Answer:

        sudo -E ./backup.sh -> Option B
      4. Quick Check:

        sudo -E preserves environment variables [OK]
      Hint: Use sudo -E to keep environment variables [OK]
      Common Mistakes:
      • Forgetting environment variables reset by sudo
      • Using sudo without -E loses variables
      • Confusing -u root with environment preservation
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard