LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-20-2013, 02:33 PM   #1
info.latawaz
Member
 
Registered: Jun 2013
Location: India
Posts: 44

Rep: Reputation: Disabled
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?
 
Old 06-20-2013, 02:50 PM   #2
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,101

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
perhaps try
Code:
sudo shutdown -h now
 
Old 06-20-2013, 02:55 PM   #3
yancek
Senior Member
 
Registered: Apr 2008
Distribution: PCLinux, Ubuntu, Slackware
Posts: 4,880

Rep: Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773Reputation: 773
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/
 
Old 06-20-2013, 03:02 PM   #4
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,886

Rep: Reputation: 1016Reputation: 1016Reputation: 1016Reputation: 1016Reputation: 1016Reputation: 1016Reputation: 1016Reputation: 1016
/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.
 
Old 06-20-2013, 06:33 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,280

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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 )
 
Old 06-20-2013, 06:44 PM   #6
frankbell
Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Mageia, Mint
Posts: 7,781

Rep: Reputation: 1469Reputation: 1469Reputation: 1469Reputation: 1469Reputation: 1469Reputation: 1469Reputation: 1469Reputation: 1469Reputation: 1469Reputation: 1469
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.
 
Old 06-21-2013, 03:26 AM   #7
info.latawaz
Member
 
Registered: Jun 2013
Location: India
Posts: 44

Original Poster
Rep: Reputation: Disabled
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?
 
Old 06-21-2013, 03:49 AM   #8
jdkaye
Senior Member
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 4,731

Rep: Reputation: Disabled
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
 
Old 06-21-2013, 04:34 AM   #9
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,280

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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.
 
Old 06-21-2013, 04:41 AM   #10
jdkaye
Senior Member
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 4,731

Rep: Reputation: Disabled
Quote:
Originally Posted by chrism01 View Post
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
 
Old 06-21-2013, 10:35 AM   #11
chetanbhasin
LQ Newbie
 
Registered: Jun 2013
Location: New Delhi, India
Distribution: Arch Linux
Posts: 18

Rep: Reputation: Disabled
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.

Last edited by chetanbhasin; 06-21-2013 at 10:36 AM. Reason: Added additional information.
 
Old 06-21-2013, 01:32 PM   #12
info.latawaz
Member
 
Registered: Jun 2013
Location: India
Posts: 44

Original Poster
Rep: Reputation: Disabled
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.
 
Old 06-21-2013, 11:23 PM   #13
jdkaye
Senior Member
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 4,731

Rep: Reputation: Disabled
Did you edit the sudoers file as I suggested in post #8?
jdk
 
Old 06-22-2013, 01:10 AM   #14
info.latawaz
Member
 
Registered: Jun 2013
Location: India
Posts: 44

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jdkaye View Post
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.

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

Last edited by info.latawaz; 06-22-2013 at 01:16 AM.
 
1 members found this post helpful.
Old 06-22-2013, 01:46 AM   #15
info.latawaz
Member
 
Registered: Jun 2013
Location: India
Posts: 44

Original Poster
Rep: Reputation: Disabled
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?
 
  


Reply

Tags
su, sudo, sudoers


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
expect command ssh sudo error linuxguru1 Linux - General 7 05-07-2013 04:40 PM
Error while running the command : sudo apxs -i -c mod_lisp2.c barun mukhopadhyay Linux - Server 14 03-14-2013 07:21 AM
sudo cd /root gives 'sudo: cd: command not found'. stf92 Linux - Newbie 4 03-03-2012 09:05 AM
b43 firmware installed , still only works after sudo modprobe b43 command issued modo505 Linux - Wireless Networking 4 07-31-2011 08:18 PM
[SOLVED] sudo: umount works, mount not works sasser Slackware 3 07-09-2010 03:01 AM


All times are GMT -5. The time now is 05:48 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration