LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   sudo and slackpkg (https://www.linuxquestions.org/questions/slackware-14/sudo-and-slackpkg-4175600650/)

deretsigernu 02-26-2017 07:34 PM

sudo and slackpkg
 
I am a novice with linux. I am trying to figure out my way with maintaining packages. I know that generally, we should avoid using the su command and then running the other commands that need elevated privileges. Except when I try to run sudo, I seem to have a problem:

Code:

bash-4.2$ sudo slackpkg info seamonkey
Password:
sudo: slackpkg: command not found
bash-4.2$

Why isn't slackpkg recognized with sudo? If I use su, I can use the slackpkg command.

Code:

bash-4.2$ su
Password:
bash-4.2# slackpkg info seamonkey

PACKAGE NAME:  seamonkey-2.46-x86_64-3_slack14.1.txz
PACKAGE LOCATION:  ./patches/packages
PAC


montagdude 02-26-2017 07:57 PM

It's because slackpkg is in /usr/sbin, which is not in your regular user's PATH. sudo will not modify your PATH or other environment variables, whereas su -l will give you essentially a true root shell.

drgibbon 02-26-2017 08:03 PM

Quote:

Originally Posted by deretsigernu (Post 5676452)
I know that generally, we should avoid using the su command and then running the other commands that need elevated privileges. Except when I try to run sudo, I seem to have a problem:

Code:

bash-4.2$ sudo slackpkg info seamonkey
Password:
sudo: slackpkg: command not found
bash-4.2$


You are free to use su or sudo, but your issue is the same as in this thread.

notKlaatu 02-26-2017 08:10 PM

First, a hint: did you look at the /etc/sudoers file?

If you do, and search for the string 'path', you'll see a comment that explains exactly what you are asking. It's actually an option, so you can modify the behaviour there.

Otherwise, you could do this, too:

Code:

$ echo $PATH
$ sudo echo $PATH

If those two values are the same, then naturally `sudo` has no effect on what directories your shell looks in for an arbitrary command you give it.

You can find out where `slackpkg` is located in the location that Slackware records anything that gets installed with `installpkg`:

Code:

$ grep slackpkg /var/log/packages/slackpkg*
So if `slackpkg` is in a location NOT in your user's or sudo's $PATH, then as far as your computer knows, `slackpkg` does not exist.

Which brings us back to your question. And the answer, as I've said, is in /etc/sudoers.

On line 59 or so:

Code:

## Uncomment to use a hard-coded PATH instead of the user's to find commands
# Defaults secure_path="blah blah blah"

So open sudoers in visudo and edit it, uncommenting that line. In so doing, you open up the PATH locations previously reserved for root, and now when you use `sudo`, you'll have the same PATH as root.

Hope that helps.

deretsigernu 02-26-2017 08:19 PM

Thanks for the helpful replies, everyone.

bassmadrigal 02-27-2017 07:57 AM

Quote:

Originally Posted by deretsigernu (Post 5676452)
I know that generally, we should avoid using the su command and then running the other commands that need elevated privileges.

This is not true. Generally, you should not be logging in as root as your primary user (especially if you intend to use a WM/DE). But when root is needed, like to run administrative tools like slackpkg, su is a perfectly acceptable approach and doesn't need to be avoided. sudo can be used in place if you set it up, but sudo was designed more for the administrator to give certain users the ability to run certain programs with root permissions, not to replace the administrator from using su (although, it can certainly be used that way, but I don't think it was the original intent behind the development of the program).

Have a look at sudo's introduction page for a more in-depth look at the program.

https://www.sudo.ws/intro.html

But, as others have pointed out, your problem is quickly solved with a modification to your /etc/sudoers file :)


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