Why is sudo -s better than sudo su?
up vote
28
down vote
favorite
I’ve seen many comments here in Ask Ubuntu regarding preference in using sudo -s
rather than sudo su
.
For me, that two commands do exactly the same. But why is sudo -s
supposed to be better?
command-line sudo su
add a comment |
up vote
28
down vote
favorite
I’ve seen many comments here in Ask Ubuntu regarding preference in using sudo -s
rather than sudo su
.
For me, that two commands do exactly the same. But why is sudo -s
supposed to be better?
command-line sudo su
1
I thinksudo -i
orsudo su
is better thansudo -s
for reasons mentioned here: ubuntuforums.org/showpost.php?p=6188826&postcount=4 Also: this is a possible duplicate of superuser.com/questions/29/…
– arrange
Oct 4 '11 at 6:27
I think this question should be moved to unix.stackexchange.com
– igi
Dec 25 '11 at 8:48
add a comment |
up vote
28
down vote
favorite
up vote
28
down vote
favorite
I’ve seen many comments here in Ask Ubuntu regarding preference in using sudo -s
rather than sudo su
.
For me, that two commands do exactly the same. But why is sudo -s
supposed to be better?
command-line sudo su
I’ve seen many comments here in Ask Ubuntu regarding preference in using sudo -s
rather than sudo su
.
For me, that two commands do exactly the same. But why is sudo -s
supposed to be better?
command-line sudo su
command-line sudo su
edited Dec 8 at 23:52
Stefan Hamcke
3911522
3911522
asked Oct 4 '11 at 4:33
fitojb
1,83811330
1,83811330
1
I thinksudo -i
orsudo su
is better thansudo -s
for reasons mentioned here: ubuntuforums.org/showpost.php?p=6188826&postcount=4 Also: this is a possible duplicate of superuser.com/questions/29/…
– arrange
Oct 4 '11 at 6:27
I think this question should be moved to unix.stackexchange.com
– igi
Dec 25 '11 at 8:48
add a comment |
1
I thinksudo -i
orsudo su
is better thansudo -s
for reasons mentioned here: ubuntuforums.org/showpost.php?p=6188826&postcount=4 Also: this is a possible duplicate of superuser.com/questions/29/…
– arrange
Oct 4 '11 at 6:27
I think this question should be moved to unix.stackexchange.com
– igi
Dec 25 '11 at 8:48
1
1
I think
sudo -i
or sudo su
is better than sudo -s
for reasons mentioned here: ubuntuforums.org/showpost.php?p=6188826&postcount=4 Also: this is a possible duplicate of superuser.com/questions/29/…– arrange
Oct 4 '11 at 6:27
I think
sudo -i
or sudo su
is better than sudo -s
for reasons mentioned here: ubuntuforums.org/showpost.php?p=6188826&postcount=4 Also: this is a possible duplicate of superuser.com/questions/29/…– arrange
Oct 4 '11 at 6:27
I think this question should be moved to unix.stackexchange.com
– igi
Dec 25 '11 at 8:48
I think this question should be moved to unix.stackexchange.com
– igi
Dec 25 '11 at 8:48
add a comment |
4 Answers
4
active
oldest
votes
up vote
26
down vote
accepted
I think sudo -s
is not "better", it's just different.
sudo -s
keeps your $HOME directory, so when you start programs, they will use your (and not root's) config files etc. Disadvantage: they can also change the ownership of your files in the $HOME directory, typical example is the .Xauthority
file, but I have never experienced a problem with that.
sudo su
or sudo -i
programs will use the root's home directory and its config files. This might be more intuitive, but it also means that it will not use any configuration you may have set for yourself (aliases, bash history,...).
1
Okay, I now understand the difference. Thank you!
– fitojb
Oct 4 '11 at 18:34
1
"sudo su" is not equivalent to "sudo -i". "sudo -i" is equivalent to "sudo su -" but "sudo su -" keeps the current working directory while "sudo -i" moves you into root's home
– Gregory Pakosz
Feb 22 '12 at 21:50
add a comment |
up vote
13
down vote
Because sudo -s
will not change your environment variables, especially $HOME
, which will stay HOME=/home/USER
. If you use sudo su
this will change to HOME=/root
which can have negative side effects when programs you start try to access your user's home directory.
So basically it's like sudo
vs gksudo
when running graphical programs.
add a comment |
up vote
5
down vote
Aside from the already mentioned differences with environment variables, I find sudo su
silly and wasteful because you are asking sudo
to run su
as root, and ask it to run a shell as root. Why ask a program to ask a program to give you a root shell, when you can just have the first program give you that shell? Does that matter in any practical sense? No, I'm just pedantic.
You’re right, it’s somewhat redundant.
– fitojb
Oct 4 '11 at 18:31
Well, not completely so: if you are usingsudo su
to be root, yes, just gosudo -i
, for example. But it does help when you want to become a different user:sudo su - myuser
.
– hggdh
Oct 4 '11 at 22:31
2
There is another difference:sudo -i
will change to/root
directory andsudo su
will stay in the directory you are.
– laurent
Oct 5 '11 at 0:05
1
@hggdh,sudo -u myuser
.
– psusi
Oct 5 '11 at 13:38
add a comment |
up vote
3
down vote
I would disagree with other answers when considering the cases when you want to log in as a user who do not have a shell. That is a very common case with users assigned to services.
Using "sudo su" will start the shell specified by the user. However in the case of a user assigned to server process, the shell is /usr/bin/false and the logging will fail. Instead you should enter as:
sudo -sHu <server-user>
that will log you in and cd to its home path, even if the user does not have a shell assigned
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f64178%2fwhy-is-sudo-s-better-than-sudo-su%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
26
down vote
accepted
I think sudo -s
is not "better", it's just different.
sudo -s
keeps your $HOME directory, so when you start programs, they will use your (and not root's) config files etc. Disadvantage: they can also change the ownership of your files in the $HOME directory, typical example is the .Xauthority
file, but I have never experienced a problem with that.
sudo su
or sudo -i
programs will use the root's home directory and its config files. This might be more intuitive, but it also means that it will not use any configuration you may have set for yourself (aliases, bash history,...).
1
Okay, I now understand the difference. Thank you!
– fitojb
Oct 4 '11 at 18:34
1
"sudo su" is not equivalent to "sudo -i". "sudo -i" is equivalent to "sudo su -" but "sudo su -" keeps the current working directory while "sudo -i" moves you into root's home
– Gregory Pakosz
Feb 22 '12 at 21:50
add a comment |
up vote
26
down vote
accepted
I think sudo -s
is not "better", it's just different.
sudo -s
keeps your $HOME directory, so when you start programs, they will use your (and not root's) config files etc. Disadvantage: they can also change the ownership of your files in the $HOME directory, typical example is the .Xauthority
file, but I have never experienced a problem with that.
sudo su
or sudo -i
programs will use the root's home directory and its config files. This might be more intuitive, but it also means that it will not use any configuration you may have set for yourself (aliases, bash history,...).
1
Okay, I now understand the difference. Thank you!
– fitojb
Oct 4 '11 at 18:34
1
"sudo su" is not equivalent to "sudo -i". "sudo -i" is equivalent to "sudo su -" but "sudo su -" keeps the current working directory while "sudo -i" moves you into root's home
– Gregory Pakosz
Feb 22 '12 at 21:50
add a comment |
up vote
26
down vote
accepted
up vote
26
down vote
accepted
I think sudo -s
is not "better", it's just different.
sudo -s
keeps your $HOME directory, so when you start programs, they will use your (and not root's) config files etc. Disadvantage: they can also change the ownership of your files in the $HOME directory, typical example is the .Xauthority
file, but I have never experienced a problem with that.
sudo su
or sudo -i
programs will use the root's home directory and its config files. This might be more intuitive, but it also means that it will not use any configuration you may have set for yourself (aliases, bash history,...).
I think sudo -s
is not "better", it's just different.
sudo -s
keeps your $HOME directory, so when you start programs, they will use your (and not root's) config files etc. Disadvantage: they can also change the ownership of your files in the $HOME directory, typical example is the .Xauthority
file, but I have never experienced a problem with that.
sudo su
or sudo -i
programs will use the root's home directory and its config files. This might be more intuitive, but it also means that it will not use any configuration you may have set for yourself (aliases, bash history,...).
answered Oct 4 '11 at 9:33
arrange
11.5k33127
11.5k33127
1
Okay, I now understand the difference. Thank you!
– fitojb
Oct 4 '11 at 18:34
1
"sudo su" is not equivalent to "sudo -i". "sudo -i" is equivalent to "sudo su -" but "sudo su -" keeps the current working directory while "sudo -i" moves you into root's home
– Gregory Pakosz
Feb 22 '12 at 21:50
add a comment |
1
Okay, I now understand the difference. Thank you!
– fitojb
Oct 4 '11 at 18:34
1
"sudo su" is not equivalent to "sudo -i". "sudo -i" is equivalent to "sudo su -" but "sudo su -" keeps the current working directory while "sudo -i" moves you into root's home
– Gregory Pakosz
Feb 22 '12 at 21:50
1
1
Okay, I now understand the difference. Thank you!
– fitojb
Oct 4 '11 at 18:34
Okay, I now understand the difference. Thank you!
– fitojb
Oct 4 '11 at 18:34
1
1
"sudo su" is not equivalent to "sudo -i". "sudo -i" is equivalent to "sudo su -" but "sudo su -" keeps the current working directory while "sudo -i" moves you into root's home
– Gregory Pakosz
Feb 22 '12 at 21:50
"sudo su" is not equivalent to "sudo -i". "sudo -i" is equivalent to "sudo su -" but "sudo su -" keeps the current working directory while "sudo -i" moves you into root's home
– Gregory Pakosz
Feb 22 '12 at 21:50
add a comment |
up vote
13
down vote
Because sudo -s
will not change your environment variables, especially $HOME
, which will stay HOME=/home/USER
. If you use sudo su
this will change to HOME=/root
which can have negative side effects when programs you start try to access your user's home directory.
So basically it's like sudo
vs gksudo
when running graphical programs.
add a comment |
up vote
13
down vote
Because sudo -s
will not change your environment variables, especially $HOME
, which will stay HOME=/home/USER
. If you use sudo su
this will change to HOME=/root
which can have negative side effects when programs you start try to access your user's home directory.
So basically it's like sudo
vs gksudo
when running graphical programs.
add a comment |
up vote
13
down vote
up vote
13
down vote
Because sudo -s
will not change your environment variables, especially $HOME
, which will stay HOME=/home/USER
. If you use sudo su
this will change to HOME=/root
which can have negative side effects when programs you start try to access your user's home directory.
So basically it's like sudo
vs gksudo
when running graphical programs.
Because sudo -s
will not change your environment variables, especially $HOME
, which will stay HOME=/home/USER
. If you use sudo su
this will change to HOME=/root
which can have negative side effects when programs you start try to access your user's home directory.
So basically it's like sudo
vs gksudo
when running graphical programs.
answered Oct 4 '11 at 8:12
htorque
46.6k32171211
46.6k32171211
add a comment |
add a comment |
up vote
5
down vote
Aside from the already mentioned differences with environment variables, I find sudo su
silly and wasteful because you are asking sudo
to run su
as root, and ask it to run a shell as root. Why ask a program to ask a program to give you a root shell, when you can just have the first program give you that shell? Does that matter in any practical sense? No, I'm just pedantic.
You’re right, it’s somewhat redundant.
– fitojb
Oct 4 '11 at 18:31
Well, not completely so: if you are usingsudo su
to be root, yes, just gosudo -i
, for example. But it does help when you want to become a different user:sudo su - myuser
.
– hggdh
Oct 4 '11 at 22:31
2
There is another difference:sudo -i
will change to/root
directory andsudo su
will stay in the directory you are.
– laurent
Oct 5 '11 at 0:05
1
@hggdh,sudo -u myuser
.
– psusi
Oct 5 '11 at 13:38
add a comment |
up vote
5
down vote
Aside from the already mentioned differences with environment variables, I find sudo su
silly and wasteful because you are asking sudo
to run su
as root, and ask it to run a shell as root. Why ask a program to ask a program to give you a root shell, when you can just have the first program give you that shell? Does that matter in any practical sense? No, I'm just pedantic.
You’re right, it’s somewhat redundant.
– fitojb
Oct 4 '11 at 18:31
Well, not completely so: if you are usingsudo su
to be root, yes, just gosudo -i
, for example. But it does help when you want to become a different user:sudo su - myuser
.
– hggdh
Oct 4 '11 at 22:31
2
There is another difference:sudo -i
will change to/root
directory andsudo su
will stay in the directory you are.
– laurent
Oct 5 '11 at 0:05
1
@hggdh,sudo -u myuser
.
– psusi
Oct 5 '11 at 13:38
add a comment |
up vote
5
down vote
up vote
5
down vote
Aside from the already mentioned differences with environment variables, I find sudo su
silly and wasteful because you are asking sudo
to run su
as root, and ask it to run a shell as root. Why ask a program to ask a program to give you a root shell, when you can just have the first program give you that shell? Does that matter in any practical sense? No, I'm just pedantic.
Aside from the already mentioned differences with environment variables, I find sudo su
silly and wasteful because you are asking sudo
to run su
as root, and ask it to run a shell as root. Why ask a program to ask a program to give you a root shell, when you can just have the first program give you that shell? Does that matter in any practical sense? No, I'm just pedantic.
answered Oct 4 '11 at 18:26
psusi
30.9k14986
30.9k14986
You’re right, it’s somewhat redundant.
– fitojb
Oct 4 '11 at 18:31
Well, not completely so: if you are usingsudo su
to be root, yes, just gosudo -i
, for example. But it does help when you want to become a different user:sudo su - myuser
.
– hggdh
Oct 4 '11 at 22:31
2
There is another difference:sudo -i
will change to/root
directory andsudo su
will stay in the directory you are.
– laurent
Oct 5 '11 at 0:05
1
@hggdh,sudo -u myuser
.
– psusi
Oct 5 '11 at 13:38
add a comment |
You’re right, it’s somewhat redundant.
– fitojb
Oct 4 '11 at 18:31
Well, not completely so: if you are usingsudo su
to be root, yes, just gosudo -i
, for example. But it does help when you want to become a different user:sudo su - myuser
.
– hggdh
Oct 4 '11 at 22:31
2
There is another difference:sudo -i
will change to/root
directory andsudo su
will stay in the directory you are.
– laurent
Oct 5 '11 at 0:05
1
@hggdh,sudo -u myuser
.
– psusi
Oct 5 '11 at 13:38
You’re right, it’s somewhat redundant.
– fitojb
Oct 4 '11 at 18:31
You’re right, it’s somewhat redundant.
– fitojb
Oct 4 '11 at 18:31
Well, not completely so: if you are using
sudo su
to be root, yes, just go sudo -i
, for example. But it does help when you want to become a different user: sudo su - myuser
.– hggdh
Oct 4 '11 at 22:31
Well, not completely so: if you are using
sudo su
to be root, yes, just go sudo -i
, for example. But it does help when you want to become a different user: sudo su - myuser
.– hggdh
Oct 4 '11 at 22:31
2
2
There is another difference:
sudo -i
will change to /root
directory and sudo su
will stay in the directory you are.– laurent
Oct 5 '11 at 0:05
There is another difference:
sudo -i
will change to /root
directory and sudo su
will stay in the directory you are.– laurent
Oct 5 '11 at 0:05
1
1
@hggdh,
sudo -u myuser
.– psusi
Oct 5 '11 at 13:38
@hggdh,
sudo -u myuser
.– psusi
Oct 5 '11 at 13:38
add a comment |
up vote
3
down vote
I would disagree with other answers when considering the cases when you want to log in as a user who do not have a shell. That is a very common case with users assigned to services.
Using "sudo su" will start the shell specified by the user. However in the case of a user assigned to server process, the shell is /usr/bin/false and the logging will fail. Instead you should enter as:
sudo -sHu <server-user>
that will log you in and cd to its home path, even if the user does not have a shell assigned
add a comment |
up vote
3
down vote
I would disagree with other answers when considering the cases when you want to log in as a user who do not have a shell. That is a very common case with users assigned to services.
Using "sudo su" will start the shell specified by the user. However in the case of a user assigned to server process, the shell is /usr/bin/false and the logging will fail. Instead you should enter as:
sudo -sHu <server-user>
that will log you in and cd to its home path, even if the user does not have a shell assigned
add a comment |
up vote
3
down vote
up vote
3
down vote
I would disagree with other answers when considering the cases when you want to log in as a user who do not have a shell. That is a very common case with users assigned to services.
Using "sudo su" will start the shell specified by the user. However in the case of a user assigned to server process, the shell is /usr/bin/false and the logging will fail. Instead you should enter as:
sudo -sHu <server-user>
that will log you in and cd to its home path, even if the user does not have a shell assigned
I would disagree with other answers when considering the cases when you want to log in as a user who do not have a shell. That is a very common case with users assigned to services.
Using "sudo su" will start the shell specified by the user. However in the case of a user assigned to server process, the shell is /usr/bin/false and the logging will fail. Instead you should enter as:
sudo -sHu <server-user>
that will log you in and cd to its home path, even if the user does not have a shell assigned
edited Nov 28 '12 at 14:25
answered Nov 9 '12 at 12:48
SystematicFrank
1313
1313
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f64178%2fwhy-is-sudo-s-better-than-sudo-su%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I think
sudo -i
orsudo su
is better thansudo -s
for reasons mentioned here: ubuntuforums.org/showpost.php?p=6188826&postcount=4 Also: this is a possible duplicate of superuser.com/questions/29/…– arrange
Oct 4 '11 at 6:27
I think this question should be moved to unix.stackexchange.com
– igi
Dec 25 '11 at 8:48