LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-16-2011, 04:56 AM   #1
idnotcrae
Member
 
Registered: May 2011
Distribution: Slackware
Posts: 121

Rep: Reputation: 0
Unhappy file read by all users !


i wanna make an alias for shutdown and reboot, and i need them to be available to all users from any terminal
alias off="/sbin/shutdown -h now"
alias reb="/sbin/shutdown -r now"
what is the file i should add these lines to ?
---
i've set the permissions for shutdown
 
Old 07-16-2011, 06:14 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
If you want aliases to be globally available and your default shell is Bash then create a file in /etc/profile.d with custom aliases readable for all. However 0) having unprivileged users execute commands to be issued by root or the admin group alone itself, 1) especially on multi-user machines and 2) with alias names that don't really make sense nor 3) allow any connected user to save files etc, etc, may cause interesting and unexpected situations. If it makes sense to you then you will also set the binary setuid-root, which isn't a security best practice anyway, or use an /etc/sudoers NOPASSWD entry so any user can actually execute the command. If in the future any damage occurs because of your craving for interesting and unexpected situations then you're completely SOL as far as I'm concerned: there's best practices, standard procedures and things you just shouldn't do.
 
Old 07-16-2011, 06:29 AM   #3
Perceptor
Member
 
Registered: Jul 2007
Location: the Future
Distribution: Slackware
Posts: 128

Rep: Reputation: 64
Instead of aliases, create scripts with the corresponding names and put them in /usr/bin for example. Thus you could use them no matter the shell.
 
1 members found this post helpful.
Old 07-16-2011, 07:23 AM   #4
idnotcrae
Member
 
Registered: May 2011
Distribution: Slackware
Posts: 121

Original Poster
Rep: Reputation: 0
i checked "profile.d" directory, it's full of shell scripts. every user read all the scripts their when he login :O ???
i just want it alias
i'm the only user of my laptop, and i dont care about security issues right now i dont have " Clasified " on my top ,um justn learning. i have 2 users on my slackware, when i want to reboot or shutdown i must switch to root first, i just want to be able to reboot my machine without switching to root, by any user and from any terminal. i know there are files in every user's home directory are read after login to set his environment variables, is there a file which is read by all users to set a global alias their ???
and if so what should i write then to make the alias work from any terminal.
 
Old 07-16-2011, 07:32 AM   #5
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,895

Rep: Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015
Quote:
Originally Posted by unSpawn View Post
If you want aliases to be globally available and your default shell is Bash then create a file in /etc/profile.d with custom aliases readable for all.
When using the Bash shell /etc/profile is not the correct place for aliases. The profile file(s) is/are only run by bash 'login shells' so any non-login child shells, such as those that get started within an xterm, aren't going to have the aliases defined. Aliases are local to the shell instance and can't be exported in the same manner as environment variables and will not be inherited by child shells.

The only file that gets run by interactive non-login bash shells is the users ~/.bashrc, but there is no global /etc/bashrc that gets run automatically. But it gets worse, because if you put the aliases in the bashrc, they're not available in 'login' bash shells as they only run the profile file(s) and not the bashrc.

By making the distinction between the two types of shell and not having a common file that gets run by both types of shell, the bash developers have made life a little difficult here.

You need to call one from the other to be sure. I've seen some people advocate calling /etc/profile from your ~/.bashrc but the bash documentation makes it clear that /etc/profile is intended to be run once only for login shells and if you want to respect that concept you want to do it the other way around with something like the following somewhere in your /etc/profile or /etc/profile.d
Code:
case $- in
*i* )  # Interactive shell
       if [ -f ~/.bashrc -a ! -z "$BASH" ]; then  # for bash shell only
          source ~/.bashrc
       fi
       ;;
esac
You can then put your aliases, Prompt string ($PS1) and so on in your ~/.bashrc and they will be available from both types of bash shell (login and non-login).

If you want to have a global bashrc shared between all users then you can create an /etc/bashrc to contain it, but you'll still need to add something like the following to each users ~/bashrc to call it
Code:
if [ -f /etc/bashrc ]; then
   source /etc/bashrc
fi
Unfortunately, this still relies on each user having a ~/.bashrc, but until bash provides support for a global /etc/bashrc in the same manner as /etc/profile, I see no way around this.


Anyway, that aside, I agree with Perceptor: wrapper scripts in /usr/local/bin will probably serve you better in this specific case. Especially so if you take care to use them safely through sudo.

Last edited by GazL; 07-16-2011 at 07:48 AM. Reason: spelling
 
1 members found this post helpful.
Old 07-16-2011, 08:20 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I'm pretty much aware of the differences in startup script usage when the shell is called as compatible 'sh' or as 'bash' and when it's called as interactive login or as interactive non-login shell or non-interactive shell. On most systems, that is. Clearly this didn't apply to slackware as it by default doesn't even carry shell initialization files in /etc/skel/, so there's no enforced uniformity to speak of anyway, except the guidelines the slackware bash manual page puts forth which I obviously should have read more closely. Anyway, "safe" usage of sudo sounds nice but it in no way addresses stuff like data loss when a user forces a 'shutdown -r now' on others...
 
Old 07-16-2011, 10:01 AM   #7
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,895

Rep: Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015
Yes, I think this is one of those issues where Slackware's critics would point to it and say "it lacks polish", while its defenders would argue that "Slackware doesn't make any assumptions and it's left to the local admin to set it up how they want it.".

Personally, I don't care for the way the Slackware shell invocation/profile setup has been done, but then I'm not that keen on the RHEL one either, and fixing a few little niggles like this is a lot easier than having to yank out whole subsystems such as pulseaudio to get to something I can live with..
 
Old 07-16-2011, 10:22 AM   #8
idnotcrae
Member
 
Registered: May 2011
Distribution: Slackware
Posts: 121

Original Poster
Rep: Reputation: 0
thanQ guys .. it's really too much valuable information n i think i'll forget abot the alias and i'll just write " /sbin/shutdown -r|h now " easier lol
 
Old 07-16-2011, 10:42 AM   #9
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,895

Rep: Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015
Quote:
Originally Posted by idnotcrae View Post
i think i'll forget abot the alias and i'll just write " /sbin/shutdown -r|h now " easier lol
Wise choice.

Personally, I just press the power button to shutdown,
and ctrl-alt-f1 + ctrl-alt-delete to reboot.

 
Old 07-16-2011, 11:37 AM   #10
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
I had to solve the same problem when I built my home theater PC. I wanted to allow anybody using the remote control to shut down the box.

In /usr/local/sbin I created three special shell scripts named safe-reboot, safe-halt, and safe-shutdown. The first two point to the safe-shutdown script and only distinguish between root and non-root accounts to use sudo when appropriate. The safe-shutdown script performs numerous checks such as whether a recording is in session and refuses to reboot/shutdown in such cases.

I modified /etc/inittab to use safe-reboot when using the three finger salute (Ctrl-Alt-Del).

I modified the KDM login manager to use those scripts rather than the standard /sbin/reboot and shutdown commands.

I placed two aliases for shutdown and reboot in /etc/bashrc that pointed to my safe-shutdown and safe-reboot scripts. I source that file in ~/.bashrc.

I added the HTPC user account name to the /etc/sudoers list and allow that account to run /sbin/halt, /sbin/shutdown, /usr/local/sbin/safe-halt, /usr/local/sbin/safe-reboot, and /usr/local/sbin/safe-shutdown.

Of course, I always can login as root (locally or ssh) and directly run /sbin/shutdown and /sbin/reboot to force either event.

A caveat with allowing any user to reboot or shutdown is determining whether other users are logged in. 'nix systems are multi-user. Those are some of the kind of tests my safe-shutdown script performs.

You can read more:

Harmonizing the Bash Startup Scripts
Improving Scripts and Safe Shutdown
 
Old 07-16-2011, 12:04 PM   #11
idnotcrae
Member
 
Registered: May 2011
Distribution: Slackware
Posts: 121

Original Poster
Rep: Reputation: 0
@GAZL --> that what i always looking for just pressing one button for every action
------------
@woodsman --> ya it's really nice idea for organizing the work , but still alot of work and i chose Slackware to avoid doing many things ;
) anyway ,i'm sure that i'll follow this harmony between scripts but not now i guess thx
 
  


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
Cat not read a file in linux, even when read permission is enabled DeepSeaNautilus Linux - Software 2 01-16-2011 04:49 PM
how to give all users read/write access to a file in the Firefox profile folder 7trek Fedora 2 11-25-2007 05:09 PM
fstab file to allow all users to read ntfs jza Linux - General 1 01-29-2004 02:05 PM
need multiple users to have read/write access to a Quickbooks file at the same time. rbelknap Linux - Security 2 10-14-2003 10:52 PM
a script that go read the users names in a file and automaticly add then with a commo tumemanques211 Programming 2 03-22-2002 02:13 PM

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

All times are GMT -5. The time now is 06:14 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
Open Source Consulting | Domain Registration