LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 04-04-2008, 08:02 AM   #1
stu_mueller
Member
 
Registered: Aug 2006
Location: England
Distribution: Slackware, Zenwalk
Posts: 114

Rep: Reputation: 15
questions about sudo


I have a couple of questions regarding sudo. I have read the man pages, and am still a bit confused

if I add

stuart ALL=NOPASSWORD: ALL to sudoers I can run any command but would have to prefix it with sudo so: 'sudo /fullpath/file'?

if I specify

stuart ALL=NOPASSWORD: /sbin/shutdown i would need to type 'sudo /sbin/shutdown'? or could I just type 'sudo shutdown'?

could I specify shutdown parameters or would they need to go in sudoers as well (stuart ALL=NOPASSWORD: /sbin/shutdown -h now)?

in all cases I would need to prefix the command with sudo?

If I wanted to chmod rc.bluetooth to make it executable and then run it would I just need sudo permissions to chmod or would I need sudo permissions to run rc.bluetooth as well?

In your experience is it best to add commands to sudoer as I find I need them or just specify ALL. (The problem with ALL is that I figure I may as well log in as root!)

Stuart
 
Old 04-04-2008, 08:23 AM   #2
mahmoud
Member
 
Registered: Apr 2006
Location: UK
Distribution: Mandriva, Debain, Redhat, Fedora, Ubuntu, FreeBSD
Posts: 269

Rep: Reputation: 30
basically any command you can issue as root u can with the sudo in front eg
sudo halt
sudo restart
sudo vim /etc/apache
sudo /etc/init.d/apache2 restart
 
Old 04-04-2008, 09:14 AM   #3
Bruce Hill
HCL Maintainer
 
Registered: Jun 2003
Location: McCalla, AL, USA
Distribution: Arch, Gentoo
Posts: 6,940

Rep: Reputation: 129Reputation: 129
Setup sudo by issuing in a terminal as root "vigr" first and add your
normal user to the wheel group. It should look like this:
Code:
wheel:x:10:root,stuart
Then setup sudo by issuing "visudo" and uncomment this line:
Code:
# %wheel ALL=(ALL)       NOPASSWD: ALL
You will be using the editor vi, and might not be familiar with it. So
let me make it simple just to get you setup.

After you issue "vigr" press the I key or press Insert and move the cursor
to the end of the wheel group line. Then type a , then your username. Then
to close the vi editor, press Esc and then :wq (semi-colon then w then q)
which means write and quit. Then for the "visudo" you can simply move the
mouse cursor to the # in the front of that line and then press x which will
remove the # then :wq

After that is done, as a normal user you can enter "sudo -i" in a terminal
and you will su to root and his home directory with his environment variable.
From there you _are_ root, and issue commands as root.

And you can issue any command that is in your normal users $PATH just by adding
sudo in front of it as stated above. However, if the command is not in your
normal users $PATH, you will have to give the full path to the command. To see
what path a user has, as that user in a terminal type $PATH and press Enter.

For instance, you would need the full path to shutdown, i.e. "sudo /sbin/shutdown -h now"

After experimenting with things similar to what you posted, this seemed to me
to be the easiest way to set it up.
 
Old 04-04-2008, 10:41 AM   #4
rworkman
Slackware Contributor
 
Registered: Oct 2004
Location: Tuscaloosa, Alabama (USA)
Distribution: Slackware
Posts: 2,559

Rep: Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351
Quote:
Originally Posted by mahmoud View Post
basically any command you can issue as root u can with the sudo in front eg
sudo halt
sudo restart
sudo vim /etc/apache
sudo /etc/init.d/apache2 restart
While your comment is not necessarily *wrong* - it needs some elaboration to be completely correct. Unlike some other distributions, Slackware leaves setup of sudo to the administrator of the computer - we don't install a "magic hammer" by default.
 
Old 04-04-2008, 10:45 AM   #5
rworkman
Slackware Contributor
 
Registered: Oct 2004
Location: Tuscaloosa, Alabama (USA)
Distribution: Slackware
Posts: 2,559

Rep: Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351
Quote:
Originally Posted by Bruce Hill View Post
And you can issue any command that is in your normal users $PATH just by adding sudo in front of it as stated above. However, if the command is not in your normal users $PATH, you will have to give the full path to the command. To see what path a user has, as that user in a terminal type $PATH and press Enter.

For instance, you would need the full path to shutdown, i.e. "sudo /sbin/shutdown -h now"
Good advice indeed about PATH issues with sudo.

Two ideas to address those (either of which works just fine, but depending on your planned usage of sudo, one is better than the other):

In /etc/profile.d/10-local.sh (create that file, as it doesn't exist, and also make it executable), put this (adjust username as appropriate):
Code:
if [ "$USER" = "rworkman" ]; then
  export PATH="${PATH}:/usr/sbin:/sbin"
fi
Alternatively, create some aliases:
Code:
if [ -e $HOME/.logout ]; then
  alias "reboot=. $HOME/.logout ; sudo /sbin/shutdown -r now"
  alias "halt=. $HOME/.logout ; sudo /sbin/shutdown -h now"
else
  alias "reboot=sudo /sbin/shutdown -r now"
  alias "halt=sudo /sbin/shutdown -h now"
fi
 
Old 04-04-2008, 03:49 PM   #6
stu_mueller
Member
 
Registered: Aug 2006
Location: England
Distribution: Slackware, Zenwalk
Posts: 114

Original Poster
Rep: Reputation: 15
Thanks Guys,

I think I have the sudo figured out now.

what I'm trying to do is write a script that will chmod a+x rc.bluetooth and start it, then bring up my hci0 interface and finally start kbluetooth

I have this working!

I then have a second script that takes down hci0, runs rc.bluetooth stop and then chmod a-x rc.bluetooth

Again this is working. What I would like to do is combine the scripts. have it check for the existence of kbluetooth in the process list (which I think I can do) and if it doesn't exist do the startup procedure, if it dows exist run the stop procedure.

The only bit I am not sure on is how to kill off kbluetooth, the most obviuos way is to say 'killall -e /usr/bin/kbluetooth'

but is that a safe way to close the application, or is there a better way? from the gui I can choose quit, but the command line doesn't give me that option. I don't know whether killing a process is hte best way of performing an exit?
 
  


Reply



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
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
cannot "sudo apt-get uptate" or "sudo" anything! plz help mdguy21061 Linux - Newbie 7 04-13-2008 11:59 PM
LXer: sudo, or not sudo: that is the question LXer Syndicated Linux News 0 02-07-2008 05:40 PM
Restricting Editing in Sudo (Advanced Sudo Question) LinuxGeek Linux - Software 4 11-04-2006 03:20 PM
Sudo without having to type "sudo?" Mitch G Linux - Security 3 09-28-2006 02:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

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