LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 07-08-2009, 02:12 AM   #1
retrodanny
Member
 
Registered: Jun 2009
Location: México
Distribution: Slackware
Posts: 38

Rep: Reputation: 2
Slackware shutdown permissions


Hi everyone
I'm having trouble with the permission to use shutdown, halt, and reboot with my user

Whenever I want to shutdown or reboot I have to become superuser.
In my regular user I get:
Code:
-bash: shutdown: command not found
or
Code:
shutdown: you must be root to do that!
(if I am already in the /sbin directory)
I'm even able to see shutdown manpages and use ls -l on it:
Code:
-rwxr-xr-x 1 root root 16864 2008-04-02 19:40 shutdown*
I read the Slackbook and tried chgrp to users but I changed back to root because it did not work

Could anyone explain how I could have my normal user have access to shutdown?

Thanks in advance, I appreciate it.
 
Old 07-08-2009, 02:25 AM   #2
karamarisan
Member
 
Registered: Jul 2009
Location: Illinois, US
Distribution: Fedora 11
Posts: 374

Rep: Reputation: 55
The program itself isn't letting you do anything useful as an unprivileged user. The purpose of the setuid bit is to deal with exactly this kind of situation. Try `chmod +s /sbin/shutdown`.

It's unrelated, but I just want to check this - when you're in /sbin, does `shutdown` run shutdown, or is it `./shutdown`? If the latter, no problem; if the former, could you `echo $PATH` and post it here?
 
Old 07-08-2009, 03:18 AM   #3
retrodanny
Member
 
Registered: Jun 2009
Location: México
Distribution: Slackware
Posts: 38

Original Poster
Rep: Reputation: 2
ok thanks a lot.. setting the user id worked... although i had to make links to reboot, halt, and shutdown on my home directory for them to work (if not I have to navigate into /sbin before running command, not sure if home was the best place to put links in)

btw,
just "shutdown" will run shutdown when in /sbin fine. Here is the path
Code:
/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib/java/bin:/usr/lib/java/jre/bin:/usr/lib/qt/bin:/usr/share/texmf/bin:.
 
Old 07-08-2009, 03:36 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
You could have just added /sbin to your PATH.

And the clean way to go about this would have been via sudoers.
Your "chmod" is going to fail with the next update. What you really
want is something in /etc/sudoers like
Code:
%users  localhost=NOPASSWD: /sbin/shutdown -h now
You could then easily alias that in your ~/.bashrc to something
like
Code:
alias shutdown='sudo /sbin/shutdown -h now'
It's slightly more hassle than chmoding the file in /sbin, but
it's clean, safe and upgrade proof.



Cheers,
Tink
 
Old 07-08-2009, 03:41 AM   #5
karamarisan
Member
 
Registered: Jul 2009
Location: Illinois, US
Distribution: Fedora 11
Posts: 374

Rep: Reputation: 55
I like his answer better. Go with that.

Okay, path stuff - when you run a program 'foo' by giving only its name, your shell searches each directory in the $PATH variable for an executable file named 'foo' and runs the first one it gets. If it makes it to the end and hasn't found anything, you get a 'command not found' error. (If you try to run ./shutdown, or /sbin/shutdown, you've given the shell the full path to the program you want to run and so no searching is required.) The reason why you are able to run shutdown without ./ when in /sbin is that . (which always means the current directory) is last in your $PATH variable. I have never used Slackware, so I don't know if that's something they do, but I can tell you that it's very unusual. If it's a default, don't worry about it, but . is not in most people's paths.

So, delete those symlinks, and add this line to .bashrc in your homedir to add /sbin to the front of your $PATH:
Code:
PATH="/sbin:$PATH"
This will not take effect until you run `source ~/.bashrc`, but will be in effect for all future shells. It should make it so you can call shutdown from any directory in the future. Note that it is important that /sbin is at the front, especially if . is in your path. Imagine if you somehow ended up with a shell script named shutdown somewhere and wanted to kill your machine - you'd be, at best, unpleasantly surprised if instead you got that script.
 
Old 07-09-2009, 02:28 AM   #6
retrodanny
Member
 
Registered: Jun 2009
Location: México
Distribution: Slackware
Posts: 38

Original Poster
Rep: Reputation: 2
Ok, I think I got the hang of PATH more or less...
I added /sbin to my PATH like this:
Code:
export PATH=$PATH:/sbin
I actually first messed it up but got it back to normal with:
Code:
uset PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib/java/bin:/usr/lib/java/jre/bin:/usr/lib/qt/bin:/usr/share/texmf/bin:.
(thank God I pasted my path in the forum... this is where I got the line from)

Anyway, now that the PATH is fixed... I'm still getting "shutdown: you must be root to do that!" when I type shutdown (from any directory now)

I added the suggested line to sudoers (really just uncommented, it was already there as an example)
The problem might be ~/.bashrc, it wasn't there!
I created the file and "alias shutdown='sudo /sbin/shutdown -h now'" is THE only line in the file...

Please help!.. not sure what exactly went wrong

btw, I really appreciate the input from both of you, and the explanation of PATH... nice and clear.
 
Old 07-09-2009, 02:52 AM   #7
retrodanny
Member
 
Registered: Jun 2009
Location: México
Distribution: Slackware
Posts: 38

Original Poster
Rep: Reputation: 2
aah! nevermind, sorry
I uncommented the wrong line (tricky little hash)
It works now! thank you so much!
 
Old 07-09-2009, 02:52 AM   #8
karamarisan
Member
 
Registered: Jul 2009
Location: Illinois, US
Distribution: Fedora 11
Posts: 374

Rep: Reputation: 55
No worries about the $PATH business - values like that (called environment variables) are reset with each new shell, and the reason why we're telling you to put modifications to them in your .bashrc is that every line in that file is run every time you run bash (i.e., every new login shell), which makes the setting essentially permanent. However, I do suggest you put /sbin at the front, not the end, for the reasons in my last post. It's a small security hole, but there's no reason to create it when the difference is just the order of some characters. : )

Now, it's entirely possible you didn't already have a .bashrc - I don't think one is created by default. You might have a .profile or something - there's a couple other files that are used in only subtly different ways. Similar to the $PATH-modifying line, adding the alias line to .bashrc isn't enough - when you `source .bashrc`, it should register with the shell that from then on, `shutdown` will be transformed into `sudo shutdown -h now`. Is that not working?


Edit: Just read that. Good to hear - good luck in the future.
 
Old 07-09-2009, 03:56 AM   #9
retrodanny
Member
 
Registered: Jun 2009
Location: México
Distribution: Slackware
Posts: 38

Original Poster
Rep: Reputation: 2
you're right.. I rebooted and now its no longer in my $PATH
I went ahead and added 'PATH="/sbin:$PATH"' to my .bashrc (thanks for explaining why sbin should go before) and ran source .bashrc
but still when I reboot it's not being added to the $PATH

I still have to cd /sbin before run reboot or halt

I still have the default $PATH:
Code:
/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib/java/bin:/usr/lib/java/jre/bin:/usr/lib/qt/bin:/usr/share/texmf/bin:.
here are the two lines in my .bashrc:
Code:
alias shutdown='sudo /sbin/shutdown -h now'
PATH="/sbin:$PATH"
 
Old 07-09-2009, 04:20 AM   #10
karamarisan
Member
 
Registered: Jul 2009
Location: Illinois, US
Distribution: Fedora 11
Posts: 374

Rep: Reputation: 55
Okay, did some quick Googling and it seems that bash may not actually source .bashrc in all cases, which would be my bad. Try copying .bashrc to .profile and see if that fixes it.

By the way - to save yourself some trouble, when testing stuff like this, you don't need to reboot every time. Just exit your terminal emulator and start a new one, or even just run bash from within bash (exit will then kill the second bash and drop you back to the first). The second one will check the files anew and will reflect changes you've made since you ran the first one.

Edit: Sorry for fumbling. I should know this, but I don't use bash - if you ever find you wish your shell were better, look into zsh. : )
 
Old 07-09-2009, 05:16 AM   #11
retrodanny
Member
 
Registered: Jun 2009
Location: México
Distribution: Slackware
Posts: 38

Original Poster
Rep: Reputation: 2
awesome!
I just did
Code:
cat .bashrc > .profile
and then closed/reopened terminal emulator (running bash again did not work for me)
echo $PATH is now
Code:
/sbin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib/java/bin:/usr/lib/java/jre/bin:/usr/lib/qt/bin:/usr/share/texmf/bin:.
!!!
so cool

... im reading about z shell... looks nice
 
Old 07-09-2009, 05:41 AM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
And the "normal" way to go about .bashrc and something that
gets pulled on login is to have a ~/.bash_login or ~/.bash_profile
that sources ~/.bashrc if it exists ...

Code:
cat ~/.bash_login
if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi
No duplication of files, no copying when you edit one of them
to make the other the same.

As for z - it's nice, it's strong, it's powerful.
Don't rely on it being installed everywhere you're
ever gonna use a unix-/linux type computer. bash
today is ubiquitous (even though AIX or Solaris
hardliners will tell you the same thing I just said
about z about bash ;}). Learn the smallest common
denominator, learn it well. Don't rely on advanced
features of certain products too much - they may
not be there on a different machine, and then it's
normally not a good time to start learning "old skool".



Cheers,
Tink

Last edited by Tinkster; 07-09-2009 at 05:45 AM.
 
Old 07-09-2009, 02:06 PM   #13
retrodanny
Member
 
Registered: Jun 2009
Location: México
Distribution: Slackware
Posts: 38

Original Poster
Rep: Reputation: 2
ok ok I think I'm getting how this works now (thanks to you guys and this manual - http://www.gnu.org/software/bash/man...line-Init-File)

allright, so I did 'vi .bash_profile' and added the line
Code:
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
then did rm .profile, closed and reopened my terminal, and echo $PATH still contains /sbin at the beginning

I know ~/.bash_profile, ~/.bash_login, ~/.profile, and ~/.bashrc are all startup files; but other than the order they are run in I don't know what they are really there for. I guess what I'm asking is, what is the difference between adding my startup commands in ~/.bashrc and using that line in ~./bash_profile to run them, and just putting the commands straight into ~/.bash_profile (or ~/.bash_login!)?
 
Old 07-09-2009, 02:22 PM   #14
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
bashrc will be valid for *any* shell you invoke, *profile and *login
will only be pulled for login-shells. What constitutes a login-shell
may depend on your DE/WM and how it invokes terminal emulators.


Have a look at
Code:
man bash
/^INVOCATION
... very enlightening.



Cheers,
Tink
 
  


Reply


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
reboot/shutdown permissions kniwor Slackware 16 06-08-2007 11:16 AM
slackware: how to shutdown (seriously) nadroj Linux - Newbie 9 04-24-2005 05:02 PM
shutdown permissions a10392 Debian 3 01-20-2005 12:58 PM
shutdown permissions elist Linux - General 2 02-01-2002 05:57 AM
Slackware shutdown jamaso Linux - General 16 11-28-2001 11:27 AM


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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration