Friday, May 3, 2024
29
rated 0 times [  29] [ 0]  / answers: 1 / hits: 118477  / 3 Years ago, wed, october 27, 2021, 3:53:19

I would like to know what is the difference between




  • su -

  • sudo bash

  • sudo sh



I cannot login as root while doing su - because I do not have the root password - I mean I have my user password with which I can sudo "command" but this password does not work for su -
I can log in as root with sudo bash with my user password and I can login while doing sudo sh but then I get a command prompt in this form
#


More From » command-line

 Answers
1

Background



In Linux (and Unix in general), there is a SuperUser named Root. The SuperUser can do anything and everything, and thus doing daily work as the SuperUser can be dangerous. You could type a command incorrectly and destroy the system. Ideally, you run as a user that has only the privileges needed for the task at hand. In some cases, this is necessarily Root, but most of the time it is a regular user.



su -



This command is used to login at root account.

By default, the Root account password is locked in Ubuntu. This means that you cannot login as Root directly or use the su command to become the Root user. However, since the Root account physically exists it is still possible to run programs with root-level privileges. This is where sudo comes in - it allows authorized users (normally "Administrative" users) to run certain programs as Root without having to know the root password.



See How to Enable Root Account.



sudo sh



This command runs "sh" as a super user.

The sh utility is a command language interpreter that shall execute commands read from a command line string, the standard input, or a specified file.



sudo bash



This command runs "bash" as a super user.

Bash is the shell, or command language interpreter. Bash is an sh-compatible shell that incorporates useful features from the Korn shell (ksh) and C shell (csh). It is intended to conform to the IEEE POSIX P1003.2/ISO 9945.2 Shell and Tools standard. It offers functional improvements over sh for both programming and interactive use. In addition, most sh scripts can be run by Bash without modification.



References: 1, 2, 3.


[#43872] Thursday, October 28, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ravturtl

Total Points: 335
Total Questions: 132
Total Answers: 110

Location: Tanzania
Member since Wed, Feb 24, 2021
3 Years ago
;