2

I have the following doubt. In a tutorial related to a software installation that I am following say that I have to execute the following commands (I am doing it into an ssh shell, so this list of steps end with the exit command):

sudo -s
apt-get update
apt-get install -y build-essential libtool libcurl4-openssl-dev libncurses5-dev libudev-dev autoconf automake screen
exit

My doubts are:

What exactly do the -s paramether after sudo command?

Searching on the web I found that:

‑s [command] The ‑s (shell) option runs the shell specified by the SHELL environment variable if it is set or the shell as specified in the password database. If a command is specified, it is passed to the shell for execution via the shell's ‑c option. If no command is specified, an interactive shell is executed

It seems to me that the sudo -s execute a command using the environment variable of the shell.

But this is not clear for me: in this case what is the command executed with the environment variable? (it only execute sudo -s and not **sudo -s [command]).

Can you explain me exactlu what it do?

Tnx

3 Answers 3

3

Quoting the man page, -s option runs the shell specified by the SHELL environment variable. So if

echo $SHELL
/bin/bash

is set, sudo -s would be equivalent to running

sudo -Eu root  /bin/bash

that is, executing the shell /bin/bash as user root, while preserving the environment variables.

2
  • mmm so in practice I have to do it because I am in ssh and doing in this way is as I am using the bash shell as root? or what am I missing? Jun 3, 2014 at 21:52
  • 1
    Exactly. From your current user, you are escalating your privilege as root user, with environment variables preserved, and then running apt-get update, and then installing your packages. Debian/Ubuntu/All linux systems require super user privilege to update package info.
    – nohup
    Jun 3, 2014 at 21:55
1

Without the option it is basically equivalent to sudo -s $SHELL. Where $SHELL is typically the path to your current shell. On Linux this is typically /bin/bash, but could also be one of many other shells.

2
  • mmm so in practice I have to do it because I am in ssh and doing in this way is as I am using the bash shell as root? or what am I missing? Jun 3, 2014 at 21:49
  • You run the command to get root privileges. If you already have root privileges, then running the command is pointless.
    – Zoredache
    Jun 3, 2014 at 21:55
1

sudo -s will start the set (by the SHELL environment variable) shell with elevated privileges.

Often, this could be similar to running sudo bash, giving you a shell where you can act as root.

If you also provide a command after sudo -s the command will be run in that elevated shell.

4
  • mmm so in practice I have to do it because I am in ssh and doing in this way is as I am using the bash shell as root? or what am I missing? Jun 3, 2014 at 21:50
  • @AndreaNobili: You would need to do this, because, usually, you never work as root. Not through SSH nor when you're working on it directly. To run the given commands, you need to be elevated. Alternatively, you could simply prefix all the commands with sudo. If you're already root, then you don't have to elevate at all. Jun 3, 2014 at 21:52
  • mmm now I think that is more clear...give me confirm about this thing: in the previous example, if I don't use sudo -s before the next commands, I can do two different things to obtain the same result: 1) put the sudo command before all the commands in the previous list OR 2) log in as root and then simply execute the commands. Is it right? in practical sudo-s is used only for reasons of convenience, right? Jun 3, 2014 at 21:57
  • 1
    @AndreaNobili: This is correct. Jun 3, 2014 at 21:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .