Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Gentoo User (http://www.linux-archive.org/gentoo-user/)
-   -   Where does sudo get the PATH ? (http://www.linux-archive.org/gentoo-user/710513-where-does-sudo-get-path.html)

"Nicolas Richard" 10-08-2012 02:20 PM

Where does sudo get the PATH ?
 
Hi everybody,

I don't understand where sudo finds the value for the PATH env variable.

Here is the output of the relevant (at least I thought they were)
commands. Can somebody explain to me why I still have
/usr/local/texlive/*2011*/bin/i386-linux in the first sudo output ? I
don't get it, and did not find anything in the man page of sudo.

Thanks in advance for your help.

youngfrog@geodiff-mac3 ~ $ bash -c 'echo $PATH'
~/bin/overrideglobal:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/games/bin:/usr/local/texlive/2012/bin/i386-linux:~/bin

youngfrog@geodiff-mac3 ~ $ source /etc/profile

youngfrog@geodiff-mac3 ~ $ bash -c 'echo $PATH'
/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/games/bin:/usr/local/texlive/2012/bin/i386-linux

youngfrog@geodiff-mac3 ~ $ sudo bash -c 'echo $PATH'
/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin:/usr/local/texlive/2011/bin/i386-linux

youngfrog@geodiff-mac3 ~ $ sudo -i bash -c 'echo $PATH'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/local/texlive/2012/bin/i386-linux:/root/bin

youngfrog@geodiff-mac3 ~ $ sudo grep -r texlive/2011 /etc

youngfrog@geodiff-mac3 ~ $ sudo grep -r texlive/2011 ~root
/root/.bash_history:cd /usr/local/texlive/2011
/root/.bash_history:grep texlive/2011 * -r
/root/.bash_history:grep texlive/2011 . -r
/root/.bash_history:grep texlive/2011 .* -r

youngfrog@geodiff-mac3 ~ $ grep -v '^#|^$' /etc/environment
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.3:/usr/local/texlive/2012/bin/i386-linux:/root/bin

--
N.R.

"J. Roeleveld" 10-09-2012 05:11 AM

Where does sudo get the PATH ?
 
Nicolas Richard <theonewiththeevillook@yahoo.fr> wrote:

>Hi everybody,
>
>I don't understand where sudo finds the value for the PATH env
>variable.
>
>Here is the output of the relevant (at least I thought they were)
>commands. Can somebody explain to me why I still have
>/usr/local/texlive/*2011*/bin/i386-linux in the first sudo output ? I
>don't get it, and did not find anything in the man page of sudo.
>
>Thanks in advance for your help.
>
>youngfrog@geodiff-mac3 ~ $ bash -c 'echo $PATH'
>~/bin/overrideglobal:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/games/bin:/usr/local/texlive/2012/bin/i386-linux:~/bin
>
>youngfrog@geodiff-mac3 ~ $ source /etc/profile
>
>youngfrog@geodiff-mac3 ~ $ bash -c 'echo $PATH'
>/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/games/bin:/usr/local/texlive/2012/bin/i386-linux
>
>youngfrog@geodiff-mac3 ~ $ sudo bash -c 'echo $PATH'
>/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin:/usr/local/texlive/2011/bin/i386-linux
>
>youngfrog@geodiff-mac3 ~ $ sudo -i bash -c 'echo $PATH'
>/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/local/texlive/2012/bin/i386-linux:/root/bin
>
>youngfrog@geodiff-mac3 ~ $ sudo grep -r texlive/2011 /etc
>
>youngfrog@geodiff-mac3 ~ $ sudo grep -r texlive/2011 ~root
>/root/.bash_history:cd /usr/local/texlive/2011
>/root/.bash_history:grep texlive/2011 * -r
>/root/.bash_history:grep texlive/2011 . -r
>/root/.bash_history:grep texlive/2011 .* -r
>
>youngfrog@geodiff-mac3 ~ $ grep -v '^#|^$' /etc/environment
>PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.3:/usr/local/texlive/2012/bin/i386-linux:/root/bin

Nicolas.

I can see several /usr/local/... paths in your /etc/environment.

--
Joost
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

"Nicolas Richard" 10-09-2012 03:03 PM

Where does sudo get the PATH ?
 
>>>>> "Joost" == J Roeleveld <joost@antarean.org> writes:

Joost> Nicolas Richard <theonewiththeevillook@yahoo.fr> wrote:
>> Here is the output of the relevant (at least I thought they were)
>> commands. Can somebody explain to me why I still have
>> /usr/local/texlive/*2011*/bin/i386-linux in the first sudo output

>> youngfrog@geodiff-mac3 ~ $ sudo bash -c 'echo $PATH'
>> /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin:/usr/local/texlive/2011/bin/i386-linux

>> youngfrog@geodiff-mac3 ~ $ grep -v '^#|^$' /etc/environment
>> PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.3:/usr/local/texlive/2012/bin/i386-linux:/root/bin

Joost> I can see several /usr/local/... paths in your
Joost> /etc/environment.


Hello Joost,

Yes, I see them too, but they are pointing to the more recent 2012
release of texlive, not the older 2011 one. What I don't understand is
where /sudo/ finds the environment when called without the "-i" option
(and in particular, that entry for texlive 2011). The manpage seems to
say that it simply uses the current environment (quoting the manpage :
"Note, however, that the actual PATH environment variable is not
modified and is passed unchanged to the program that sudo executes.")
but that does not seem right.

--
N.

"J. Roeleveld" 10-10-2012 09:49 AM

Where does sudo get the PATH ?
 
On Tue, October 9, 2012 5:03 pm, Nicolas Richard wrote:
>>>>>> "Joost" == J Roeleveld <joost@antarean.org> writes:
>
> Joost> Nicolas Richard <theonewiththeevillook@yahoo.fr> wrote:
> >> Here is the output of the relevant (at least I thought they were)
> >> commands. Can somebody explain to me why I still have
> >> /usr/local/texlive/*2011*/bin/i386-linux in the first sudo output
>
> >> youngfrog@geodiff-mac3 ~ $ sudo bash -c 'echo $PATH'
> >> /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin:/usr/local/texlive/2011/bin/i386-linux
>
> >> youngfrog@geodiff-mac3 ~ $ grep -v '^#|^$' /etc/environment
> >> PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.3:/usr/local/texlive/2012/bin/i386-linux:/root/bin
>
> Joost> I can see several /usr/local/... paths in your
> Joost> /etc/environment.
>
>
> Hello Joost,
>
> Yes, I see them too, but they are pointing to the more recent 2012
> release of texlive, not the older 2011 one. What I don't understand is
> where /sudo/ finds the environment when called without the "-i" option
> (and in particular, that entry for texlive 2011). The manpage seems to
> say that it simply uses the current environment (quoting the manpage :
> "Note, however, that the actual PATH environment variable is not
> modified and is passed unchanged to the program that sudo executes.")
> but that does not seem right.
>
> --
> N.

What do you get with "echo $PATH" when not using sudo?


--
Joost

"J. Roeleveld" 10-10-2012 09:50 AM

Where does sudo get the PATH ?
 
On Tue, October 9, 2012 5:03 pm, Nicolas Richard wrote:
>>>>>> "Joost" == J Roeleveld <joost@antarean.org> writes:
>
> Joost> Nicolas Richard <theonewiththeevillook@yahoo.fr> wrote:
> >> Here is the output of the relevant (at least I thought they were)
> >> commands. Can somebody explain to me why I still have
> >> /usr/local/texlive/*2011*/bin/i386-linux in the first sudo output
>
> >> youngfrog@geodiff-mac3 ~ $ sudo bash -c 'echo $PATH'
> >> /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin:/usr/local/texlive/2011/bin/i386-linux
>
> >> youngfrog@geodiff-mac3 ~ $ grep -v '^#|^$' /etc/environment
> >> PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.3:/usr/local/texlive/2012/bin/i386-linux:/root/bin
>
> Joost> I can see several /usr/local/... paths in your
> Joost> /etc/environment.
>
>
> Hello Joost,
>
> Yes, I see them too, but they are pointing to the more recent 2012
> release of texlive, not the older 2011 one. What I don't understand is
> where /sudo/ finds the environment when called without the "-i" option
> (and in particular, that entry for texlive 2011). The manpage seems to
> say that it simply uses the current environment (quoting the manpage :
> "Note, however, that the actual PATH environment variable is not
> modified and is passed unchanged to the program that sudo executes.")
> but that does not seem right.

And, what is in the .bash_profile and .bashrc files in your homedir and in
root's homedir?


--
Joost

"Nicolas Richard" 10-10-2012 02:57 PM

Where does sudo get the PATH ?
 
>>>>> "Joost" == J Roeleveld <joost@antarean.org> writes:
Joost> And, what is in the .bash_profile and .bashrc files in your
Joost> homedir and in root's homedir?

In my homedir:
.bash_profile loads .bashrc
.bashrc says export PATH="~/bin/overrideglobal:${PATH}:~/bin" (and
defines some aliases)

In root's: I have no such files.

Maybe it would be less distracting if I don't use a shell at all :

youngfrog@geodiff-mac3 ~ $ sudo -i env | grep ^PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/local/texlive/2012/bin/i386-linux:/root/bin

youngfrog@geodiff-mac3 ~ $ sudo env | grep ^PATH
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin:/usr/local/texlive/2011/bin/i386-linux


Joost> What do you get with "echo $PATH" when not using sudo?

You mean, when I'm logged in as root ? Then it's the same as when using
sudo -i.

N.

Joost Roeleveld 10-10-2012 06:43 PM

Where does sudo get the PATH ?
 
On Wednesday, October 10, 2012 04:57:50 PM Nicolas Richard wrote:
> >>>>> "Joost" == J Roeleveld <joost@antarean.org> writes:
> Joost> And, what is in the .bash_profile and .bashrc files in your
> Joost> homedir and in root's homedir?
>
> In my homedir:
> .bash_profile loads .bashrc
> .bashrc says export PATH="~/bin/overrideglobal:${PATH}:~/bin" (and
> defines some aliases)

Does it load any global default?

> In root's: I have no such files.
>
> Maybe it would be less distracting if I don't use a shell at all :
>
> youngfrog@geodiff-mac3 ~ $ sudo -i env | grep ^PATH
> PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/
> usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/local/texlive/2012/bin/i386-linux:/
> root/bin
>
> youngfrog@geodiff-mac3 ~ $ sudo env | grep ^PATH
> PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin:/
> usr/local/texlive/2011/bin/i386-linux
>
>
> Joost> What do you get with "echo $PATH" when not using sudo?
>
> You mean, when I'm logged in as root ? Then it's the same as when using
> sudo -i.

No, when you're logged in as your normal user.

In other words, what is in the environment when you are normally logged in?

--
Joost

"Nicolas Richard" 10-11-2012 02:25 PM

Where does sudo get the PATH ?
 
Joost Roeleveld <joost@antarean.org> writes:
> On Wednesday, October 10, 2012 04:57:50 PM Nicolas Richard wrote:
>> In my homedir:
>> .bash_profile loads .bashrc
>> .bashrc says export PATH="~/bin/overrideglobal:${PATH}:~/bin" (and
>> defines some aliases)
>
> Does it load any global default?

No. Here are the full files, omitting comments and empty lines :

youngfrog@geodiff-mac3 ~ $ grep -vH '^#|^$' .bashrc .bash_profile
.bashrc:export PATH="~/bin/overrideglobal:${PATH}:~/bin"
.bashrc:if [[ $- != *i* ]] ; then
.bashrc: # Shell is non-interactive. Be done now!
.bashrc: return
.bashrc:fi
.bashrc:UPDATEGITREPO="~/TeX/ ~/BSSM/2011/notes-de-conf/ ~/org/ ~/BSSM/2012"
.bashrc:export UPDATEGITREPO
.bashrc:alias ll="ls -lA"
.bashrc:alias l="ls -CF"
.bashrc:alias cp="cp -i"
.bashrc:alias rm="rm -i"
.bashrc:alias mv="mv -i"
.bash_profile:[[ -f ~/.bashrc ]] && . ~/.bashrc

> In other words, what is in the environment when you are normally
> logged in?

Ok, I thought my original post contained it. In fact that was part of my
original post :

youngfrog@geodiff-mac3 ~ $ bash -c 'echo $PATH'
~/bin/overrideglobal:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/games/bin:/usr/local/texlive/2012/bin/i386-linux:~/bin

and I forgot to mention that it was the same as :
youngfrog@geodiff-mac3 ~ $ env | grep ^PATH
PATH=~/bin/overrideglobal:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/games/bin:/usr/local/texlive/2012/bin/i386-linux:~/bin

and yet the same as :
youngfrog@geodiff-mac3 ~ $ echo $PATH
~/bin/overrideglobal:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/games/bin:/usr/local/texlive/2012/bin/i386-linux:~/bin

Thanks for trying btw. I certainly did something really stupid to set
the path the first time, but can't see where.

N.

Pandu Poluan 10-11-2012 04:24 PM

Where does sudo get the PATH ?
 
On Oct 11, 2012 9:29 PM, "Nicolas Richard" <theonewiththeevillook@yahoo.fr> wrote:

>

> Joost Roeleveld <joost@antarean.org> writes:

> > On Wednesday, October 10, 2012 04:57:50 PM Nicolas Richard wrote:

> >> In my homedir:

> >> .bash_profile loads .bashrc

> >> .bashrc says export PATH="~/bin/overrideglobal:${PATH}:~/bin" (and

> >> defines some aliases)

> >

> > Does it load any global default?

>

> No. Here are the full files, omitting comments and empty lines :

>

> youngfrog@geodiff-mac3 ~ $ grep -vH '^#|^$' .bashrc .bash_profile

> .bashrc:export PATH="~/bin/overrideglobal:${PATH}:~/bin"

> .bashrc:if [[ $- != *i* ]] ; then

> .bashrc: * * * *# Shell is non-interactive. *Be done now!

> .bashrc: * * * *return

> .bashrc:fi

> .bashrc:UPDATEGITREPO="~/TeX/ ~/BSSM/2011/notes-de-conf/ ~/org/ ~/BSSM/2012"

> .bashrc:export UPDATEGITREPO

> .bashrc:alias ll="ls -lA"

> .bashrc:alias l="ls -CF"

> .bashrc:alias cp="cp -i"

> .bashrc:alias rm="rm -i"

> .bashrc:alias mv="mv -i"

> .bash_profile:[[ -f ~/.bashrc ]] && . ~/.bashrc

>

> > In other words, what is in the environment when you are normally

> > logged in?

>

> Ok, I thought my original post contained it. In fact that was part of my

> original post :

>

> youngfrog@geodiff-mac3 ~ $ bash -c 'echo $PATH'

> ~/bin/overrideglobal:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/games/bin:/usr/local/texlive/2012/bin/i386-linux:~/bin

>

> and I forgot to mention that it was the same as :

> youngfrog@geodiff-mac3 ~ $ env | grep ^PATH

> PATH=~/bin/overrideglobal:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/games/bin:/usr/local/texlive/2012/bin/i386-linux:~/bin

>

> and yet the same as :

> youngfrog@geodiff-mac3 ~ $ echo $PATH

> ~/bin/overrideglobal:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.4:/usr/games/bin:/usr/local/texlive/2012/bin/i386-linux:~/bin

>

> Thanks for trying btw. I certainly did something really stupid to set

> the path the first time, but can't see where.

>


A bit desperate, but try :


grep -R "texlive/2011" /etc/*


Rgds,

"Nicolas Richard" 10-11-2012 04:50 PM

Where does sudo get the PATH ?
 
Pandu Poluan <pandu@poluan.info> writes:
> A bit desperate, but try :
>
> grep -R "texlive/2011" /etc/*

I tried that already

youngfrog@geodiff-mac3 ~ $ sudo grep -r texlive/2011 /etc

youngfrog@geodiff-mac3 ~ $ sudo grep -r texlive/2011 ~root
/root/.bash_history:cd /usr/local/texlive/2011
/root/.bash_history:grep texlive/2011 * -r
/root/.bash_history:grep texlive/2011 . -r
/root/.bash_history:grep texlive/2011 .* -r

--
N.


All times are GMT. The time now is 10:44 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.