LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command 'su -' works but 'sudo' gives error (https://www.linuxquestions.org/questions/linux-newbie-8/command-su-works-but-sudo-gives-error-4175466776/)

info.latawaz 06-20-2013 02:33 PM

Command 'su -' works but 'sudo' gives error
 
Hi,

I have set root password and I login to root with 'su -' and that password and it is successful. This i am doing from a user account that I am using for myself.

Now I am trying to simply type 'sudo' followed by the command and it asks for password. Entering root password shows
Quote:

'Sorry, try again'
. Instead of entering root password, if I enter the user account password, it says
Quote:

sudo: poweroff: command not found
I am trying to give a user, permission to execute poweroff command which is here: /sbin/poweroff

What should I do?

frieza 06-20-2013 02:50 PM

perhaps try
Code:

sudo shutdown -h now

yancek 06-20-2013 02:55 PM

Have you configured or enabled sudo on Slackware?

http://linuxg.net/how-to-install-and...-slackware-14/

Have you tried using the full path?

http://www.linuxquestions.org/questi...-found-792446/

suicidaleggroll 06-20-2013 03:02 PM

/sbin is typically not in the normal users' PATH. You can use the full path to it if you want, or you can add /sbin to the PATH, or you can use shutdown -h.

chrism01 06-20-2013 06:33 PM

Show the sudoers file, but, as above, its always a good idea to specify the complete cmd path for privileged cmds.
BTW, with sudo cmd, its always the user's passwd, not root's (& vice versa for su obviously ;) )

frankbell 06-20-2013 06:44 PM

If I recall correctly, Slackware does not automatically configure the sudoers file. It does not share Ubuntu's sudo fetish.

To implement sudo, you will need to edit the sudoers file using the visudo command.

info.latawaz 06-21-2013 03:26 AM

I didn't know that sudo needs to be installed. But I followed the link and did what was asked. Finally got this message.

Quote:

root@localhost:~# slackpkg install sudo

Looking for sudo in package list. Please wait... DONE

No packages match the pattern for install. Try:

/usr/sbin/slackpkg reinstall|upgrade
After this, I added path /sbin to $PATH with this
Quote:

export PATH=$PATH:/sbin
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib64/kde4/libexec:/usr/lib64/qt/bin:/usr/share/texmf/bin:.:/sbin
So it seems PATH /sbin has been added. Before that I had added below line to /etc/sudoer
Quote:

myuser localhost=/sbin/halt;/sbin/poweroff;/sbin/shutdown
After this, as myuser, I am doing this
Quote:

sudo poweroff
Password:
Sorry, user myuser is not allowed to execute '/sbin/poweroff' as root on localhost.
What am I missing?

jdkaye 06-21-2013 03:49 AM

Have you edited the sudoers file (usually /etc/sudoers). You need to add a line like this:
Before:
Code:

# User privilege specification
root    ALL=(ALL:ALL) ALL

After:
Code:

# User privilege specification
root    ALL=(ALL:ALL) ALL
myuser  ALL=(ALL:ALL) ALL

Or something like that.
jdk

chrism01 06-21-2013 04:34 AM

No point in putting root in sudoers file; he/she already has total power ;)

sudo entry should be comma-with-space separated see http://www.sudo.ws/sudo/sudoers.man.html.
Never use the keyword ALL if you can avoid it; always be specific.

jdkaye 06-21-2013 04:41 AM

Quote:

Originally Posted by chrism01 (Post 4975941)
No point in putting root in sudoers file; he/she already has total power ;)

sudo entry should be comma-with-space separated see http://www.sudo.ws/sudo/sudoers.man.html.
Never use the keyword ALL if you can avoid it; always be specific.

I didn't; Debian did. I haven't ever touched the sudoers file except to add my own userid. I don't do anything with root. Just use it as it comes out of the box.
ciao,
jdk

chetanbhasin 06-21-2013 10:35 AM

Do you have sudo installed?

If not, you can probably do that by logging into root and installing sudo with your preferred package manager.

P.S. You can also try removing and purging and then reinstalling sudo to check if it works this time.

info.latawaz 06-21-2013 01:32 PM

Sudo is installed
Code:

myuser@localhost:~$ sudo
usage: sudo [-D level] -h | -K | -k | -V
usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid]
usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user name] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid] [VAR=value] [-i|-s]
            [<command>]
usage: sudo -e [-AknS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] file ...

When I execute poweroff with full path, I get below output.
Code:

myuser@localhost:~$ sudo /sbin/poweroff
Password:
Sorry, user myuser is not allowed to execute '/sbin/poweroff' as root on localhost.


jdkaye 06-21-2013 11:23 PM

Did you edit the sudoers file as I suggested in post #8?
jdk

info.latawaz 06-22-2013 01:10 AM

Quote:

Originally Posted by jdkaye (Post 4976421)
Did you edit the sudoers file as I suggested in post #8?
jdk

Nope, I did not. I don't want to give complete permission to the user. Then there is no point in giving permission at all. I can just 'su -' and get my work done.

I am hoping for something more accurate like 'poweroff' and 'shutdown'. Ofcourse I can 'su -' and do the same but I am trying to do it differently.:D

But I have added the below line already in /etc/sudoers
Code:

myuser localhost=/sbin/halt;/sbin/poweroff;/sbin/shutdown
I says
Code:

'myuser' is not allowed to execute the execute '/sbin/poweroff' as root on local host

info.latawaz 06-22-2013 01:46 AM

I made changes in sudoers and this is what I did
Code:

myuser ALL=(ALL) /sbin/halt,/sbin/poweroff,/sbin/shutdown
I then executed 'sudo poweroff' and got 'Command not found'. I then executed 'sudo /sbin/poweroff' and it worked.

Now the only thing that is left is to remove /sbin, as in to use 'sudo poweroff'. I think adding path /sbin to $PATH should work. Right? If so, how and where do I add path?

info.latawaz 06-22-2013 02:18 AM

Finally figured it out.

Here are the steps in a bottleneck to help a fellow in need.
1) Edit /etc/sudoers with visudo and add this line.
Code:

<your-user> ALL=(ALL) <commands-you-want(with path) or ALL(for all commands)>
2) Type sudo to check if it is installed. If not, then install it.(http://linuxg.net/how-to-install-and...-slackware-14/)
3) Once installed, open /etc/profile, look for PATH and add ':/sbin' at the end before double quotes or other path if the command is in another folder and save.
4) Logout
5) Login back with the user and try 'sudo <your-command>. It should work now. :D

vineethsp 06-27-2013 11:45 AM

Quote:

Originally Posted by info.latawaz (Post 4976461)
I made changes in sudoers and this is what I did
Code:

myuser ALL=(ALL) /sbin/halt,/sbin/poweroff,/sbin/shutdown
I then executed 'sudo poweroff' and got 'Command not found'. I then executed 'sudo /sbin/poweroff' and it worked.

Now the only thing that is left is to remove /sbin, as in to use 'sudo poweroff'. I think adding path /sbin to $PATH should work. Right? If so, how and where do I add path?

Hi,

You can export the path as
Code:

export PATH=/sbin:$PATH
/sbin is the new path you would like to add while
$PATH has the existing paths you need to retain in the new path.

Hope this is Helpful.
CheeerrZZZZ

info.latawaz 06-27-2013 02:15 PM

I tried export but the path it had added was removed when I restarted the system. However, editing directly in the file worked.

This problem has been solved. Thanks for the input though. Much Appreciated. :D

linuxzilla.com 06-28-2013 05:59 AM

Quote:

Originally Posted by jdkaye (Post 4975924)
Have you edited the sudoers file (usually /etc/sudoers). You need to add a line like this:
Before:
Code:

# User privilege specification
root    ALL=(ALL:ALL) ALL

After:
Code:

# User privilege specification
root    ALL=(ALL:ALL) ALL
myuser  ALL=(ALL:ALL) ALL

Or something like that.
jdk

That is the correct answer and I use to do that for a sudo user. After that for logging in, use the following command to get into root:

sudo su -

and give myuser password again!

suicidaleggroll 06-28-2013 08:53 PM

Quote:

Originally Posted by info.latawaz (Post 4979788)
I tried export but the path it had added was removed when I restarted the system. However, editing directly in the file worked.

This problem has been solved. Thanks for the input though. Much Appreciated. :D

Environment variable settings are unique to that terminal and its child processes. If you want a change to the environment variable to be applied to all future terminals then you need to add it to your .bashrc or .bash_profile file.

unSpawn 07-02-2013 12:22 PM

Quote:

Originally Posted by linuxzilla.com (Post 4980173)
That is the correct answer and

No it isn't and chrism01 already posted how sane folks should use Sudo (http://www.linuxquestions.org/questi...#post4975941):
Quote:

Originally Posted by chrism01
Never use the keyword ALL if you can avoid it; always be specific.



All times are GMT -5. The time now is 07:15 AM.