LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-22-2011, 03:18 PM   #1
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Rep: Reputation: 43
Sudo sometimes changes PATH and not others?


If I try "shutdown" as a normal user on Debian it give the "command not found" error. OK it's not in my PATH. But if I "sudo shutdown" it works. Somehow sudo seems to change my PATH.

Do the same in Slackware however and sudo makes no difference, I get "command not found" each time.

Anyone care to enlighten me?
 
Old 01-22-2011, 04:06 PM   #2
alar
Member
 
Registered: Sep 2003
Location: Canada
Distribution: Fedora 30
Posts: 341

Rep: Reputation: 37
sudo can read from the path /sbin
a regular user can not


su - should do it in slackware

Last edited by alar; 01-22-2011 at 04:07 PM.
 
Old 01-22-2011, 04:12 PM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
I don't believe the cause is sudo.

The sudo command lets a user run a command as another user. It probably does this by launching another shell process as that user, and then runs the command. I emphasize "probably" because I haven't looked at the code to know for sure.

Assuming that is the case, then the PATH when the command is executed will be created/modified by shell startup files (e.g. for bash: /etc/profile, ${HOME}/.bash_profile, etc. -- see man bash for a list of the files bash reads).

So, it's likely that any PATH problems you encounter are a result of the shell startup files for the user you're trying to act as.
 
Old 01-22-2011, 05:24 PM   #4
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
@alar - I think you misunderstand, I have sudo installed and configured in slackware, as I do in debian. My point being that it (apparently) behaves differently in the two different distros despite being the same package.



@Dark_Helmet - that sounds like it makes sense, as the profile, bash_profile bashrc etc settings are almost certainly different in the two distros. I'll look into it, thanks.
 
Old 01-26-2011, 01:02 PM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
First make sure there is not any aliases for sudo.

Secondly, check each users PATH. shutdown is usually in /sbin and not all users have /sbin in their default path, Slackware seems to have this for regular users by default.

Thirdly, it's not sudo but rather the default path of the user.

Remember, when you run sudo, it retains your current users default path. When you use sudo to su as another user (example root), you are still basically carrying over your environment settings, which includes path, etc. To take on the full path of another user, that's when you do something like sudo su - <user>
 
Old 01-26-2011, 01:21 PM   #6
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
Quote:
Originally Posted by trickykid View Post
First make sure there is not any aliases for sudo.

Secondly, check each users PATH. shutdown is usually in /sbin and not all users have /sbin in their default path, Slackware seems to have this for regular users by default.

Thirdly, it's not sudo but rather the default path of the user.

Remember, when you run sudo, it retains your current users default path. When you use sudo to su as another user (example root), you are still basically carrying over your environment settings, which includes path, etc. To take on the full path of another user, that's when you do something like sudo su - <user>
Thanks for the reply trickykid but I don't think you read the question properly. I already said in the opening post that neither user has /sbin in their PATH. I also said that it is only the preface sudo command that allows me to run shutdown, but that this behaviour is inconsistant between the two users/distros.

So why can I run sudo shutdown from my normal debian user account but not my normal slackware user account, when both accounts have the same PATH?

If Dark_Helmet were correct then the new shell process would gain root bash profile settings (and therefore PATH) as well as root authority, in both cases.

(No aliases are set btw).

Last edited by spoovy; 01-26-2011 at 01:24 PM.
 
Old 01-26-2011, 01:25 PM   #7
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by spoovy View Post
So why can I run sudo shutdown from my normal debian user account but not my normal slackware user account, when both accounts have the same PATH?
So did you also verify if there's not a link or another shutdown command in the given path that the other distro doesn't have?

Honestly, why does it matter? Different distro's are just that, they're slightly different from one another. If you want your distro's to behave the same, run the same distro on both machines.
 
Old 01-26-2011, 04:40 PM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
You can setup sudo to change the environment (and with this the PATH). This configuration is done in the sudoers-file. Compare the sudoers-file on both systems and check
Code:
man sudoers
for more info on that.
 
Old 01-27-2011, 05:43 AM   #9
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
Quote:
Originally Posted by trickykid View Post
Honestly, why does it matter? Different distro's are just that, they're slightly different from one another. If you want your distro's to behave the same, run the same distro on both machines.
Why does it matter? Why are you even posting that stupid question? Because i'm curious about linux; that's why i'm posting on a forum called 'linuxquestions' dummy.

@TobiSDG - Thanks i'll check that out.

Last edited by spoovy; 01-27-2011 at 05:44 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenBSD 4.7, sudo, PATH not being preserved. bluesword1969 *BSD 1 06-08-2010 04:11 PM
Sudo path variable error andrewbonney Linux - Newbie 2 05-29-2010 03:07 AM
PATH, dot dir, and sudo yogaboy2 Linux - General 5 07-06-2009 08:14 PM
How to setup user's PATH env when sudo command in RHEL5? sailer_sh Red Hat 3 12-22-2008 07:36 PM
Can a sudo user be allowed use relative path yksudha Linux - Security 1 06-11-2008 01:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration