View previous topic :: View next topic |
Author |
Message |
skorefish Apprentice
Joined: 21 Jun 2015 Posts: 285
|
Posted: Sat Dec 30, 2017 9:57 am Post subject: /etc/init.d/net.wlp2s0 restart for user[solved] |
|
|
hi,
how can i grand access for a normal user to /etc/init.d/net.wlp2s0 restart
without using sudo and without typing the passwd??
i was thinking
/usr/share/polkit-1/actions/restartWifi.policy
Code: | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
<policyconfig>
<vendor>void</vendor>
<vendor_url></vendor_url>
<icon_name>computer</icon_name>
<action id="restartWifi">
<description>Restart wifi</description>
<message>...</message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>no</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/etc/init.d/net.wlp2s0</annotate>
</action>
</policyconfig> |
/etc/polkit-1/rules.d/10-restartWifi.rules
Code: | polkit.addRule(function(action, subject) {
if (action.id == "restartWifi" )
{
return polkit.Result.YES;
}
});
|
but it doesn't work
Last edited by skorefish on Thu Jan 11, 2018 11:03 pm; edited 2 times in total |
|
Back to top |
|
|
charles17 Advocate
Joined: 02 Mar 2008 Posts: 3664
|
Posted: Sat Dec 30, 2017 10:09 am Post subject: Re: /etc/init.d/net.wlp2s0 restart for user??? |
|
|
The question is: Why would you want to do that? |
|
Back to top |
|
|
skorefish Apprentice
Joined: 21 Jun 2015 Posts: 285
|
Posted: Sat Dec 30, 2017 10:16 am Post subject: |
|
|
Quote: | charles17:The question is: Why would you want to do that? |
for my .bash_profile to execute
Code: | status=$(/etc/init.d/net.wlp2s0 status|grep -o started);
if [ "$status" != "started" ];
then
/etc/init.d/net.wlp2s0 restart
startxfce4 --with-ck-launch
fi
cpupower --cpu all frequency-set --freq 800MHz
|
i don't start net.wlp2s0 with rc because this is so much slower
i don't want to use a window manager |
|
Back to top |
|
|
krinn Watchman
Joined: 02 May 2003 Posts: 7470
|
Posted: Sat Dec 30, 2017 12:19 pm Post subject: |
|
|
you could start a script that loop for a file when you boot, and if the file is there it just start the service, this way your user can create the file, but the script that will start the service has rights to do so.
Code: | #!/bin/bash
while [ ! -f /tmp/whatevername ]
do
sleep 1
done
/etc/init.d/net.wlp2s0 restart |
and your .bash_profile adapt to
Code: | then
touch /tmp/whatevername
startxfce4 --with-ck-launch
|
|
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Sat Dec 30, 2017 12:29 pm Post subject: Re: /etc/init.d/net.wlp2s0 restart for user??? |
|
|
skorefish wrote: | without using sudo and without typing the passwd? |
Why that restriction? A particular sudo rule for that particular command and your user with NOPASSWD sounds to me to be the correct solution. |
|
Back to top |
|
|
skorefish Apprentice
Joined: 21 Jun 2015 Posts: 285
|
Posted: Sat Dec 30, 2017 2:00 pm Post subject: |
|
|
Quote: | you could start a script that loop for a file when you boot, |
very interesting method !!
and Code: | david asus=(ALL) NOPASSWD:/etc/init.d/net.wlp2s0,/etc/sudoers,/sbin/shutdown,/usr/bin/cpupower |
works,but what about just typing Code: | /etc/init.d/net.wlp2s0 restart | without restrictions! Is this possible for a user?
What's the danger in restarting the wifi as a user? |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21607
|
Posted: Sat Dec 30, 2017 6:24 pm Post subject: |
|
|
It is not a question of whether it is dangerous to let the user restart wireless. There is no restriction on running that command as a user. However, if you want it to succeed, it needs permission to do things that users normally cannot do. If you have this in a startup script anyway, why do you need the user to be able to run this without sudo? Would it not be easier to define a wrapper that will sudo the script for you? |
|
Back to top |
|
|
|