Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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.

share|improve this answer
    
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? –  AndreaNobili Jun 3 '14 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 '14 at 21:55

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.

share|improve this answer
    
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? –  AndreaNobili Jun 3 '14 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 '14 at 21:55

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.

share|improve this answer
    
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? –  AndreaNobili Jun 3 '14 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. –  Oliver Salzburg Jun 3 '14 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? –  AndreaNobili Jun 3 '14 at 21:57
1  
@AndreaNobili: This is correct. –  Oliver Salzburg Jun 3 '14 at 21:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.