Is it possible for root to execute a command as non-root?
I am a root user, and suppose I want to run any application as another user. Is this possible, without switching to another user?
Something like
# google-chrome user=abc
I am actually executing a CLI program as a non-root user. I have set the sticky bit on and I am using setuid, so the program runs with root privileges. Now I am using system()
within the program to invoke a GUI app. But I don't want to run it as root, so I want to temporarily drop root privileges only for that call.
linux user su
add a comment |
I am a root user, and suppose I want to run any application as another user. Is this possible, without switching to another user?
Something like
# google-chrome user=abc
I am actually executing a CLI program as a non-root user. I have set the sticky bit on and I am using setuid, so the program runs with root privileges. Now I am using system()
within the program to invoke a GUI app. But I don't want to run it as root, so I want to temporarily drop root privileges only for that call.
linux user su
1
Are you really running as root most of the time?
– Keith
Sep 29 '12 at 13:38
1
@Keith nothing in the question implies most of the time.
– kojiro
Sep 29 '12 at 14:07
Or not, that's why I ask for clarification.
– Keith
Sep 29 '12 at 18:46
Yes that is how the first program for each user is run. The first process on the system is run as root. There are a lot of ways to drop privilege, including all the ways that can escalate privilege, plus some more.
– ctrl-alt-delor
Sep 29 '12 at 21:14
add a comment |
I am a root user, and suppose I want to run any application as another user. Is this possible, without switching to another user?
Something like
# google-chrome user=abc
I am actually executing a CLI program as a non-root user. I have set the sticky bit on and I am using setuid, so the program runs with root privileges. Now I am using system()
within the program to invoke a GUI app. But I don't want to run it as root, so I want to temporarily drop root privileges only for that call.
linux user su
I am a root user, and suppose I want to run any application as another user. Is this possible, without switching to another user?
Something like
# google-chrome user=abc
I am actually executing a CLI program as a non-root user. I have set the sticky bit on and I am using setuid, so the program runs with root privileges. Now I am using system()
within the program to invoke a GUI app. But I don't want to run it as root, so I want to temporarily drop root privileges only for that call.
linux user su
linux user su
edited Jun 17 '17 at 18:26
Glorfindel
1,43041220
1,43041220
asked Sep 29 '12 at 8:09
adnan kamiliadnan kamili
2811515
2811515
1
Are you really running as root most of the time?
– Keith
Sep 29 '12 at 13:38
1
@Keith nothing in the question implies most of the time.
– kojiro
Sep 29 '12 at 14:07
Or not, that's why I ask for clarification.
– Keith
Sep 29 '12 at 18:46
Yes that is how the first program for each user is run. The first process on the system is run as root. There are a lot of ways to drop privilege, including all the ways that can escalate privilege, plus some more.
– ctrl-alt-delor
Sep 29 '12 at 21:14
add a comment |
1
Are you really running as root most of the time?
– Keith
Sep 29 '12 at 13:38
1
@Keith nothing in the question implies most of the time.
– kojiro
Sep 29 '12 at 14:07
Or not, that's why I ask for clarification.
– Keith
Sep 29 '12 at 18:46
Yes that is how the first program for each user is run. The first process on the system is run as root. There are a lot of ways to drop privilege, including all the ways that can escalate privilege, plus some more.
– ctrl-alt-delor
Sep 29 '12 at 21:14
1
1
Are you really running as root most of the time?
– Keith
Sep 29 '12 at 13:38
Are you really running as root most of the time?
– Keith
Sep 29 '12 at 13:38
1
1
@Keith nothing in the question implies most of the time.
– kojiro
Sep 29 '12 at 14:07
@Keith nothing in the question implies most of the time.
– kojiro
Sep 29 '12 at 14:07
Or not, that's why I ask for clarification.
– Keith
Sep 29 '12 at 18:46
Or not, that's why I ask for clarification.
– Keith
Sep 29 '12 at 18:46
Yes that is how the first program for each user is run. The first process on the system is run as root. There are a lot of ways to drop privilege, including all the ways that can escalate privilege, plus some more.
– ctrl-alt-delor
Sep 29 '12 at 21:14
Yes that is how the first program for each user is run. The first process on the system is run as root. There are a lot of ways to drop privilege, including all the ways that can escalate privilege, plus some more.
– ctrl-alt-delor
Sep 29 '12 at 21:14
add a comment |
4 Answers
4
active
oldest
votes
A portable solution would be:
su abc -c google-chrome
However, as google-chrome is requiring X11 access, this will likely fail unless you unsecured it, which would be a very bad idea, especially while running as root.
If X11 tunelling/forwarding is allowed, a better way would be
ssh -X abc@localhost google-chrome
or
ssh -Y abc@localhost google-chrome
Why would the ssh approach be any better? Wouldn't this still run using the root user's X session?
– Steve
May 13 '18 at 21:04
1
@Steve Usingsu abc -c google-chrome
will likely fail in the first place becauseabc
cannot use root's session,.Xauthority
being unreadable forabc
.
– jlliagre
May 13 '18 at 21:22
Oops sorry I misunderstood you, I thought you meant it would be better from a security perspective
– Steve
May 13 '18 at 21:24
add a comment |
Short answer: "Yes, this is possible".
if you like to execute a non-X application then just use the following command:
sudo -u abc command
If you like to run some X application as another user but with your own desktop first you need to create a helper script, that will make your life simpler
- create a bin folder under your home directory:
mkdir -p ~/bin
and using your favorite text editor create a file ~/bin/xsudo
as follows:
#!/bin/bash
# (C) serge 2012
# The script is licensed to all users of StackExchange family free of charge
# Fixes/Enhancements to the script are greatly appreciated.
#
# SUDO_ASKPASS has to be set to the path of ssh-askpass
# fix the following two lines if your distribution does not match this autodetection
. /etc/profile.d/gnome-ssh-askpass.sh
export SUDO_ASKPASS="${SSH_ASKPASS}"
SUDOUSERNAME="$1"
shift
xauth nlist "${DISPLAY}"|sudo -HA -u $SUDOUSERNAME env --unset=XAUTHORITY
bash -c "xauth nmerge - ; $*"
then make it executable:
chmod +x ~/bin/xsudo
and use it the same way as sudo
but without any switches:
xsudo user application
Enjoy.
P.S. Starting xsession
from the root
account is strongly discouraged!
Did you try it ? I'm afraid this particular example can't work.
– jlliagre
Sep 29 '12 at 10:56
Yes, because in order to start an X application from another user session you have to allow access to you display. But this is also possible. Unfortunately I do not remember how exactly this to be done.
– Serge
Sep 29 '12 at 11:03
@jlliagre However, I remember how to start an X app on the same host in a tricky way:ssh -X abc@localhost google-chrome
:)
– Serge
Sep 29 '12 at 11:07
Hmm... I'm writing in comments what you already posted 22 mins ago...
– Serge
Sep 29 '12 at 11:15
But you still have 6 up votes for a non working solution while I only got one for a correct one. StackExchange model is sometimes quite frustrating ...
– jlliagre
Sep 29 '12 at 13:24
|
show 4 more comments
There is a way to run chromium when logged in to the root user. If you open it normally, it will give you an error like "chromium cannot be run as root."
To run it without the error, right click your desktop, create a new launcher with the command: chromium-browser --user-data-dir
. You can name it what you want, save it, when you open it, it will give you the chromium browser. (Works in Ubuntu 10.04.4 LTS)
add a comment |
#! /bin/bash
# (GPL3+) Alberto Salvia Novella (es20490446e)
execute () {
function="${1}"
command="${2}"
error=$(eval "${command}" 2>&1 >"/dev/null")
if [ ${?} -ne 0 ]; then
echo "${function}: $error"
exit 1
fi
}
executeAsNonAdmin () {
function="${1}"
command="${2}"
eval setPasswordAsker="SUDO_ASKPASS=/usr/libexec/openssh/ssh-askpass"
run="runuser ${SUDO_USER} --session-command="${setPasswordAsker}" --command="${command}""
execute "${function}" "${run}"
}
executeAsNonAdmin "" "${@}"
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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',
autoActivateHeartbeat: false,
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%2fsuperuser.com%2fquestions%2f481080%2fis-it-possible-for-root-to-execute-a-command-as-non-root%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
A portable solution would be:
su abc -c google-chrome
However, as google-chrome is requiring X11 access, this will likely fail unless you unsecured it, which would be a very bad idea, especially while running as root.
If X11 tunelling/forwarding is allowed, a better way would be
ssh -X abc@localhost google-chrome
or
ssh -Y abc@localhost google-chrome
Why would the ssh approach be any better? Wouldn't this still run using the root user's X session?
– Steve
May 13 '18 at 21:04
1
@Steve Usingsu abc -c google-chrome
will likely fail in the first place becauseabc
cannot use root's session,.Xauthority
being unreadable forabc
.
– jlliagre
May 13 '18 at 21:22
Oops sorry I misunderstood you, I thought you meant it would be better from a security perspective
– Steve
May 13 '18 at 21:24
add a comment |
A portable solution would be:
su abc -c google-chrome
However, as google-chrome is requiring X11 access, this will likely fail unless you unsecured it, which would be a very bad idea, especially while running as root.
If X11 tunelling/forwarding is allowed, a better way would be
ssh -X abc@localhost google-chrome
or
ssh -Y abc@localhost google-chrome
Why would the ssh approach be any better? Wouldn't this still run using the root user's X session?
– Steve
May 13 '18 at 21:04
1
@Steve Usingsu abc -c google-chrome
will likely fail in the first place becauseabc
cannot use root's session,.Xauthority
being unreadable forabc
.
– jlliagre
May 13 '18 at 21:22
Oops sorry I misunderstood you, I thought you meant it would be better from a security perspective
– Steve
May 13 '18 at 21:24
add a comment |
A portable solution would be:
su abc -c google-chrome
However, as google-chrome is requiring X11 access, this will likely fail unless you unsecured it, which would be a very bad idea, especially while running as root.
If X11 tunelling/forwarding is allowed, a better way would be
ssh -X abc@localhost google-chrome
or
ssh -Y abc@localhost google-chrome
A portable solution would be:
su abc -c google-chrome
However, as google-chrome is requiring X11 access, this will likely fail unless you unsecured it, which would be a very bad idea, especially while running as root.
If X11 tunelling/forwarding is allowed, a better way would be
ssh -X abc@localhost google-chrome
or
ssh -Y abc@localhost google-chrome
answered Sep 29 '12 at 10:51
jlliagrejlliagre
11.9k32540
11.9k32540
Why would the ssh approach be any better? Wouldn't this still run using the root user's X session?
– Steve
May 13 '18 at 21:04
1
@Steve Usingsu abc -c google-chrome
will likely fail in the first place becauseabc
cannot use root's session,.Xauthority
being unreadable forabc
.
– jlliagre
May 13 '18 at 21:22
Oops sorry I misunderstood you, I thought you meant it would be better from a security perspective
– Steve
May 13 '18 at 21:24
add a comment |
Why would the ssh approach be any better? Wouldn't this still run using the root user's X session?
– Steve
May 13 '18 at 21:04
1
@Steve Usingsu abc -c google-chrome
will likely fail in the first place becauseabc
cannot use root's session,.Xauthority
being unreadable forabc
.
– jlliagre
May 13 '18 at 21:22
Oops sorry I misunderstood you, I thought you meant it would be better from a security perspective
– Steve
May 13 '18 at 21:24
Why would the ssh approach be any better? Wouldn't this still run using the root user's X session?
– Steve
May 13 '18 at 21:04
Why would the ssh approach be any better? Wouldn't this still run using the root user's X session?
– Steve
May 13 '18 at 21:04
1
1
@Steve Using
su abc -c google-chrome
will likely fail in the first place because abc
cannot use root's session, .Xauthority
being unreadable for abc
.– jlliagre
May 13 '18 at 21:22
@Steve Using
su abc -c google-chrome
will likely fail in the first place because abc
cannot use root's session, .Xauthority
being unreadable for abc
.– jlliagre
May 13 '18 at 21:22
Oops sorry I misunderstood you, I thought you meant it would be better from a security perspective
– Steve
May 13 '18 at 21:24
Oops sorry I misunderstood you, I thought you meant it would be better from a security perspective
– Steve
May 13 '18 at 21:24
add a comment |
Short answer: "Yes, this is possible".
if you like to execute a non-X application then just use the following command:
sudo -u abc command
If you like to run some X application as another user but with your own desktop first you need to create a helper script, that will make your life simpler
- create a bin folder under your home directory:
mkdir -p ~/bin
and using your favorite text editor create a file ~/bin/xsudo
as follows:
#!/bin/bash
# (C) serge 2012
# The script is licensed to all users of StackExchange family free of charge
# Fixes/Enhancements to the script are greatly appreciated.
#
# SUDO_ASKPASS has to be set to the path of ssh-askpass
# fix the following two lines if your distribution does not match this autodetection
. /etc/profile.d/gnome-ssh-askpass.sh
export SUDO_ASKPASS="${SSH_ASKPASS}"
SUDOUSERNAME="$1"
shift
xauth nlist "${DISPLAY}"|sudo -HA -u $SUDOUSERNAME env --unset=XAUTHORITY
bash -c "xauth nmerge - ; $*"
then make it executable:
chmod +x ~/bin/xsudo
and use it the same way as sudo
but without any switches:
xsudo user application
Enjoy.
P.S. Starting xsession
from the root
account is strongly discouraged!
Did you try it ? I'm afraid this particular example can't work.
– jlliagre
Sep 29 '12 at 10:56
Yes, because in order to start an X application from another user session you have to allow access to you display. But this is also possible. Unfortunately I do not remember how exactly this to be done.
– Serge
Sep 29 '12 at 11:03
@jlliagre However, I remember how to start an X app on the same host in a tricky way:ssh -X abc@localhost google-chrome
:)
– Serge
Sep 29 '12 at 11:07
Hmm... I'm writing in comments what you already posted 22 mins ago...
– Serge
Sep 29 '12 at 11:15
But you still have 6 up votes for a non working solution while I only got one for a correct one. StackExchange model is sometimes quite frustrating ...
– jlliagre
Sep 29 '12 at 13:24
|
show 4 more comments
Short answer: "Yes, this is possible".
if you like to execute a non-X application then just use the following command:
sudo -u abc command
If you like to run some X application as another user but with your own desktop first you need to create a helper script, that will make your life simpler
- create a bin folder under your home directory:
mkdir -p ~/bin
and using your favorite text editor create a file ~/bin/xsudo
as follows:
#!/bin/bash
# (C) serge 2012
# The script is licensed to all users of StackExchange family free of charge
# Fixes/Enhancements to the script are greatly appreciated.
#
# SUDO_ASKPASS has to be set to the path of ssh-askpass
# fix the following two lines if your distribution does not match this autodetection
. /etc/profile.d/gnome-ssh-askpass.sh
export SUDO_ASKPASS="${SSH_ASKPASS}"
SUDOUSERNAME="$1"
shift
xauth nlist "${DISPLAY}"|sudo -HA -u $SUDOUSERNAME env --unset=XAUTHORITY
bash -c "xauth nmerge - ; $*"
then make it executable:
chmod +x ~/bin/xsudo
and use it the same way as sudo
but without any switches:
xsudo user application
Enjoy.
P.S. Starting xsession
from the root
account is strongly discouraged!
Did you try it ? I'm afraid this particular example can't work.
– jlliagre
Sep 29 '12 at 10:56
Yes, because in order to start an X application from another user session you have to allow access to you display. But this is also possible. Unfortunately I do not remember how exactly this to be done.
– Serge
Sep 29 '12 at 11:03
@jlliagre However, I remember how to start an X app on the same host in a tricky way:ssh -X abc@localhost google-chrome
:)
– Serge
Sep 29 '12 at 11:07
Hmm... I'm writing in comments what you already posted 22 mins ago...
– Serge
Sep 29 '12 at 11:15
But you still have 6 up votes for a non working solution while I only got one for a correct one. StackExchange model is sometimes quite frustrating ...
– jlliagre
Sep 29 '12 at 13:24
|
show 4 more comments
Short answer: "Yes, this is possible".
if you like to execute a non-X application then just use the following command:
sudo -u abc command
If you like to run some X application as another user but with your own desktop first you need to create a helper script, that will make your life simpler
- create a bin folder under your home directory:
mkdir -p ~/bin
and using your favorite text editor create a file ~/bin/xsudo
as follows:
#!/bin/bash
# (C) serge 2012
# The script is licensed to all users of StackExchange family free of charge
# Fixes/Enhancements to the script are greatly appreciated.
#
# SUDO_ASKPASS has to be set to the path of ssh-askpass
# fix the following two lines if your distribution does not match this autodetection
. /etc/profile.d/gnome-ssh-askpass.sh
export SUDO_ASKPASS="${SSH_ASKPASS}"
SUDOUSERNAME="$1"
shift
xauth nlist "${DISPLAY}"|sudo -HA -u $SUDOUSERNAME env --unset=XAUTHORITY
bash -c "xauth nmerge - ; $*"
then make it executable:
chmod +x ~/bin/xsudo
and use it the same way as sudo
but without any switches:
xsudo user application
Enjoy.
P.S. Starting xsession
from the root
account is strongly discouraged!
Short answer: "Yes, this is possible".
if you like to execute a non-X application then just use the following command:
sudo -u abc command
If you like to run some X application as another user but with your own desktop first you need to create a helper script, that will make your life simpler
- create a bin folder under your home directory:
mkdir -p ~/bin
and using your favorite text editor create a file ~/bin/xsudo
as follows:
#!/bin/bash
# (C) serge 2012
# The script is licensed to all users of StackExchange family free of charge
# Fixes/Enhancements to the script are greatly appreciated.
#
# SUDO_ASKPASS has to be set to the path of ssh-askpass
# fix the following two lines if your distribution does not match this autodetection
. /etc/profile.d/gnome-ssh-askpass.sh
export SUDO_ASKPASS="${SSH_ASKPASS}"
SUDOUSERNAME="$1"
shift
xauth nlist "${DISPLAY}"|sudo -HA -u $SUDOUSERNAME env --unset=XAUTHORITY
bash -c "xauth nmerge - ; $*"
then make it executable:
chmod +x ~/bin/xsudo
and use it the same way as sudo
but without any switches:
xsudo user application
Enjoy.
P.S. Starting xsession
from the root
account is strongly discouraged!
edited Sep 29 '12 at 20:58
answered Sep 29 '12 at 8:35
SergeSerge
2,532815
2,532815
Did you try it ? I'm afraid this particular example can't work.
– jlliagre
Sep 29 '12 at 10:56
Yes, because in order to start an X application from another user session you have to allow access to you display. But this is also possible. Unfortunately I do not remember how exactly this to be done.
– Serge
Sep 29 '12 at 11:03
@jlliagre However, I remember how to start an X app on the same host in a tricky way:ssh -X abc@localhost google-chrome
:)
– Serge
Sep 29 '12 at 11:07
Hmm... I'm writing in comments what you already posted 22 mins ago...
– Serge
Sep 29 '12 at 11:15
But you still have 6 up votes for a non working solution while I only got one for a correct one. StackExchange model is sometimes quite frustrating ...
– jlliagre
Sep 29 '12 at 13:24
|
show 4 more comments
Did you try it ? I'm afraid this particular example can't work.
– jlliagre
Sep 29 '12 at 10:56
Yes, because in order to start an X application from another user session you have to allow access to you display. But this is also possible. Unfortunately I do not remember how exactly this to be done.
– Serge
Sep 29 '12 at 11:03
@jlliagre However, I remember how to start an X app on the same host in a tricky way:ssh -X abc@localhost google-chrome
:)
– Serge
Sep 29 '12 at 11:07
Hmm... I'm writing in comments what you already posted 22 mins ago...
– Serge
Sep 29 '12 at 11:15
But you still have 6 up votes for a non working solution while I only got one for a correct one. StackExchange model is sometimes quite frustrating ...
– jlliagre
Sep 29 '12 at 13:24
Did you try it ? I'm afraid this particular example can't work.
– jlliagre
Sep 29 '12 at 10:56
Did you try it ? I'm afraid this particular example can't work.
– jlliagre
Sep 29 '12 at 10:56
Yes, because in order to start an X application from another user session you have to allow access to you display. But this is also possible. Unfortunately I do not remember how exactly this to be done.
– Serge
Sep 29 '12 at 11:03
Yes, because in order to start an X application from another user session you have to allow access to you display. But this is also possible. Unfortunately I do not remember how exactly this to be done.
– Serge
Sep 29 '12 at 11:03
@jlliagre However, I remember how to start an X app on the same host in a tricky way:
ssh -X abc@localhost google-chrome
:)– Serge
Sep 29 '12 at 11:07
@jlliagre However, I remember how to start an X app on the same host in a tricky way:
ssh -X abc@localhost google-chrome
:)– Serge
Sep 29 '12 at 11:07
Hmm... I'm writing in comments what you already posted 22 mins ago...
– Serge
Sep 29 '12 at 11:15
Hmm... I'm writing in comments what you already posted 22 mins ago...
– Serge
Sep 29 '12 at 11:15
But you still have 6 up votes for a non working solution while I only got one for a correct one. StackExchange model is sometimes quite frustrating ...
– jlliagre
Sep 29 '12 at 13:24
But you still have 6 up votes for a non working solution while I only got one for a correct one. StackExchange model is sometimes quite frustrating ...
– jlliagre
Sep 29 '12 at 13:24
|
show 4 more comments
There is a way to run chromium when logged in to the root user. If you open it normally, it will give you an error like "chromium cannot be run as root."
To run it without the error, right click your desktop, create a new launcher with the command: chromium-browser --user-data-dir
. You can name it what you want, save it, when you open it, it will give you the chromium browser. (Works in Ubuntu 10.04.4 LTS)
add a comment |
There is a way to run chromium when logged in to the root user. If you open it normally, it will give you an error like "chromium cannot be run as root."
To run it without the error, right click your desktop, create a new launcher with the command: chromium-browser --user-data-dir
. You can name it what you want, save it, when you open it, it will give you the chromium browser. (Works in Ubuntu 10.04.4 LTS)
add a comment |
There is a way to run chromium when logged in to the root user. If you open it normally, it will give you an error like "chromium cannot be run as root."
To run it without the error, right click your desktop, create a new launcher with the command: chromium-browser --user-data-dir
. You can name it what you want, save it, when you open it, it will give you the chromium browser. (Works in Ubuntu 10.04.4 LTS)
There is a way to run chromium when logged in to the root user. If you open it normally, it will give you an error like "chromium cannot be run as root."
To run it without the error, right click your desktop, create a new launcher with the command: chromium-browser --user-data-dir
. You can name it what you want, save it, when you open it, it will give you the chromium browser. (Works in Ubuntu 10.04.4 LTS)
edited Jun 30 '14 at 12:51
HopelessN00b
1,82931829
1,82931829
answered Jun 30 '14 at 12:17
user299161user299161
111
111
add a comment |
add a comment |
#! /bin/bash
# (GPL3+) Alberto Salvia Novella (es20490446e)
execute () {
function="${1}"
command="${2}"
error=$(eval "${command}" 2>&1 >"/dev/null")
if [ ${?} -ne 0 ]; then
echo "${function}: $error"
exit 1
fi
}
executeAsNonAdmin () {
function="${1}"
command="${2}"
eval setPasswordAsker="SUDO_ASKPASS=/usr/libexec/openssh/ssh-askpass"
run="runuser ${SUDO_USER} --session-command="${setPasswordAsker}" --command="${command}""
execute "${function}" "${run}"
}
executeAsNonAdmin "" "${@}"
add a comment |
#! /bin/bash
# (GPL3+) Alberto Salvia Novella (es20490446e)
execute () {
function="${1}"
command="${2}"
error=$(eval "${command}" 2>&1 >"/dev/null")
if [ ${?} -ne 0 ]; then
echo "${function}: $error"
exit 1
fi
}
executeAsNonAdmin () {
function="${1}"
command="${2}"
eval setPasswordAsker="SUDO_ASKPASS=/usr/libexec/openssh/ssh-askpass"
run="runuser ${SUDO_USER} --session-command="${setPasswordAsker}" --command="${command}""
execute "${function}" "${run}"
}
executeAsNonAdmin "" "${@}"
add a comment |
#! /bin/bash
# (GPL3+) Alberto Salvia Novella (es20490446e)
execute () {
function="${1}"
command="${2}"
error=$(eval "${command}" 2>&1 >"/dev/null")
if [ ${?} -ne 0 ]; then
echo "${function}: $error"
exit 1
fi
}
executeAsNonAdmin () {
function="${1}"
command="${2}"
eval setPasswordAsker="SUDO_ASKPASS=/usr/libexec/openssh/ssh-askpass"
run="runuser ${SUDO_USER} --session-command="${setPasswordAsker}" --command="${command}""
execute "${function}" "${run}"
}
executeAsNonAdmin "" "${@}"
#! /bin/bash
# (GPL3+) Alberto Salvia Novella (es20490446e)
execute () {
function="${1}"
command="${2}"
error=$(eval "${command}" 2>&1 >"/dev/null")
if [ ${?} -ne 0 ]; then
echo "${function}: $error"
exit 1
fi
}
executeAsNonAdmin () {
function="${1}"
command="${2}"
eval setPasswordAsker="SUDO_ASKPASS=/usr/libexec/openssh/ssh-askpass"
run="runuser ${SUDO_USER} --session-command="${setPasswordAsker}" --command="${command}""
execute "${function}" "${run}"
}
executeAsNonAdmin "" "${@}"
answered Jan 18 at 12:21
Alberto Salvia NovellaAlberto Salvia Novella
1461
1461
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f481080%2fis-it-possible-for-root-to-execute-a-command-as-non-root%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
Are you really running as root most of the time?
– Keith
Sep 29 '12 at 13:38
1
@Keith nothing in the question implies most of the time.
– kojiro
Sep 29 '12 at 14:07
Or not, that's why I ask for clarification.
– Keith
Sep 29 '12 at 18:46
Yes that is how the first program for each user is run. The first process on the system is run as root. There are a lot of ways to drop privilege, including all the ways that can escalate privilege, plus some more.
– ctrl-alt-delor
Sep 29 '12 at 21:14