• Post author:
  • Post category:Blog
  • Reading time:4 mins read
  • Post last modified:November 26, 2024

Which of these commands will create a new shell logged in as the root user?

  • sudo
  • su

For more questions and answers go to the below link:

Linux Unhatched Assignments Assessment Exam Answers

The command that will create a new shell logged in as the root user is:

su


Explanation of su

What Does su Do?

  • The su command stands for “substitute user” or “switch user”.
  • By default, running su without specifying a username switches the current session to the root user and opens a new shell.
  • To access the root shell, you will be prompted to enter the root password.

Key Details:

  • A new shell environment is created as the root user.
  • The user remains logged in as root until they type exit or close the shell.
  • If you specify another username (e.g., su username), it switches to that user’s account instead.

Example:

su
  • Prompts for the root password and logs you into a new root shell.

Explanation of sudo

What Does sudo Do?

  • The sudo command stands for “superuser do”.
  • It allows a non-root user to execute a single command with root privileges without creating a new shell.
  • Unlike su, it doesn’t switch the user or open a new shell; instead, it temporarily grants administrative privileges for the command being run.

Key Details:

  • Does not open a new shell; it only executes the specified command with elevated privileges.
  • Prompts for the password of the current user, not the root password (as long as the user is in the sudoers file).

Example:

sudo apt-get update
  • Executes the apt-get update command with root privileges but doesn’t log you into a root shell.

Key Differences Between su and sudo

Feature su sudo
Creates new shell? Yes No
Password required? Root password Current user’s password
Scope of privileges Entire shell session Single command
Best suited for Logging into a persistent root shell Running occasional admin tasks

Which Command Should You Use?

  • Use su:
    • When you need to work in a root shell for an extended period.
    • When managing systems where sudo is not configured or enabled.
    • If you have access to the root password.
  • Use sudo:
    • When you want to execute individual administrative tasks without fully switching to the root user.
    • When working on systems where root login is disabled for security reasons (common in modern Linux systems).

Summary

  • su will create a new shell logged in as the root user.
  • sudo executes a single command with root privileges but does not create a new shell.
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments