LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command 'su -' works but 'sudo' gives error (http://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?


All times are GMT -5. The time now is 03:30 PM.