LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
perhaps try
Code:
sudo shutdown -h now
 
Old 06-20-2013, 02:55 PM   #3
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,492

Rep: Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488
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
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
/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
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,311
Blog Entries: 28

Rep: Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137
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
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

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
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

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
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:21 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