LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-04-2017, 07:59 PM   #1
ag33k
Member
 
Registered: Mar 2013
Location: Portugal
Distribution: Slackware
Posts: 98

Rep: Reputation: Disabled
force a reboot as a regular user


1) I want to be able to run this as a regular user,

Code:
#!/bin/bash

echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger
If I run a script with that it won't work!
Because I'm not able to run anything like that as regular user!

For now it works on root .bashrc like this,

Code:
function  reboot_force() {

    echo 1 > /proc/sys/kernel/sysrq
    echo b > /proc/sysrq-trigger

}
I have this on my slackwarearm on RPi3 (and also in a laptop) and it would be nice using this as a regular user. Because my Pi sometimes hangs on due to firefox.

2) Being able to do this as regular user have any security concerns?

EDIT: I post it here because is not only arm related!
 
Old 01-04-2017, 08:55 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Try it as
Code:
echo 1 | sudo tee /proc/sys/kernel/sysrq
echo b | sudo tee /proc/sysrq-trigger
 
Old 01-04-2017, 09:24 PM   #3
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
I'm not sure if you can do that as a normal user without using sudo. Whenever you give a user the ability to run commands as root, there's always security concerns, but there's ways to minimize those concerns by limiting what your user can run with sudo. The best way to do that would be to create a script that is only writeable by root with the commands you need to run, then give your user the ability to only execute that script using sudo.

You could create a script like /usr/bin/force-reboot containing your commands:

Code:
#!/bin/bash

echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger
Then you would need to run visudo to allow your user to run sudo force-reboot with root permissions. By default, it will use the vi editor, but if you don't like it, you can override it with a different editor using EDITOR=nano visudo (replacing nano with a different editor if you don't like nano).

Then you would just add the below in that file (it doesn't need to be in any specific place). You can either choose to have to enter your user's password or no password (obviously requiring a password is a little more secure).

Code:
ag33k ALL=NOPASSWD: /usr/bin/force-reboot
If you want to restrict it to only work when your on your local machine (so it wouldn't work when you're ssh'ed in), you can change the "ALL" to localhost, and if you want to type your password, you would change NOPASSWD to PASSWD.
 
2 members found this post helpful.
Old 01-05-2017, 01:33 AM   #4
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
The quick and dirty solution to a forced reboot in default Slackware is in /etc/inittab
Code:
# What to do at the "Three Finger Salute".
ca::ctrlaltdel:/sbin/shutdown -t5 -r now
 
Old 01-05-2017, 01:53 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,846

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
yes, why don't you execute:
Code:
sudo /sbin/shutdown -r now
#or
sudo /sbin/reboot -f
#long time ago I used to force reboot by:
sudo init 6
but I would say you only need to restart firefox (probably)
 
Old 01-05-2017, 06:22 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,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
Please note that Slackware does not configure the sudoers file by default. The fascination with sudo is very much a *buntu thing.

If you want to use sudo on Slackware, you will first have to edit sudoers, as root, using the visudo command.
 
1 members found this post helpful.
Old 01-05-2017, 06:28 PM   #7
jamison20000e
Senior Member
 
Registered: Nov 2005
Location: ...uncanny valley... infinity\1975; (randomly born:) Milwaukee, WI, US( + travel,) Earth&Mars (I wish,) END BORDER$!◣◢┌∩┐ Fe26-E,e...
Distribution: any GPL that work on freest-HW; has been KDE, CLI, Novena-SBC but open.. http://goo.gl/NqgqJx &c ;-)
Posts: 4,888
Blog Entries: 2

Rep: Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567
Pi, unplug it?
 
Old 01-07-2017, 09:32 PM   #8
ag33k
Member
 
Registered: Mar 2013
Location: Portugal
Distribution: Slackware
Posts: 98

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bassmadrigal View Post
I'm not sure if you can do that as a normal user without using sudo. Whenever you give a user the ability to run commands as root, there's always security concerns, but there's ways to minimize those concerns by limiting what your user can run with sudo. The best way to do that would be to create a script that is only writeable by root with the commands you need to run, then give your user the ability to only execute that script using sudo.

You could create a script like /usr/bin/force-reboot containing your commands:

Code:
#!/bin/bash

echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger
Then you would need to run visudo to allow your user to run sudo force-reboot with root permissions. By default, it will use the vi editor, but if you don't like it, you can override it with a different editor using EDITOR=nano visudo (replacing nano with a different editor if you don't like nano).

Then you would just add the below in that file (it doesn't need to be in any specific place). You can either choose to have to enter your user's password or no password (obviously requiring a password is a little more secure).

Code:
ag33k ALL=NOPASSWD: /usr/bin/force-reboot
If you want to restrict it to only work when your on your local machine (so it wouldn't work when you're ssh'ed in), you can change the "ALL" to localhost, and if you want to type your password, you would change NOPASSWD to PASSWD.
Thanks

Code:
# ls -lisah /usr/bin/force-reboot  
1500248 4.0K -rwxr-xr-x 1 pi pi 126 Jan  5 01:14 /usr/bin/force-reboot
force-reboot
Code:
#!/bin/bash

echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger
/etc/sudoers

Code:
pi ALL=NOPASSWD: /usr/bin/force-reboot

Output:

Code:
$ force-reboot 
/usr/bin/force-reboot: line 5: /proc/sys/kernel/sysrq: Permission denied
/usr/bin/force-reboot: line 6: /proc/sysrq-trigger: Permission denied
Only works as root!
 
Old 01-07-2017, 10:19 PM   #9
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
Quote:
Originally Posted by ag33k View Post
Output:

Code:
$ force-reboot 
/usr/bin/force-reboot: line 5: /proc/sys/kernel/sysrq: Permission denied
/usr/bin/force-reboot: line 6: /proc/sysrq-trigger: Permission denied
Only works as root!
You still need to run it with sudo. For anything you set up with /etc/sudoers, you need to use the sudo command to allow for those extra privileges.

Code:
sudo force-reboot
 
2 members found this post helpful.
Old 01-07-2017, 10:34 PM   #10
ag33k
Member
 
Registered: Mar 2013
Location: Portugal
Distribution: Slackware
Posts: 98

Original Poster
Rep: Reputation: Disabled
It works!

Thanks
 
Old 01-08-2017, 04:41 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,846

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
if your issue is now solved please mark the thread solved.
Also if you want to say thanks just click on yes.
 
  


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
Can't force reboot from program drb Linux - Newbie 4 07-07-2011 07:06 PM
How to make libata.force=1.5G work without reboot? sscn Linux - Software 2 06-07-2011 04:24 AM
pc name changed after regular reboot Lord of the Board Linux - Newbie 2 10-01-2006 03:24 PM
login regular but start a server process automatically after reboot powah Linux - Newbie 6 05-24-2005 07:21 AM
Intermittent disconnects force reboot (RH8) NLawrence Linux - Networking 0 02-28-2004 01:29 PM

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

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