# /etc/init.d/net.wlp2s0 restart for user[solved]

## skorefish

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

```
<?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

```
polkit.addRule(function(action, subject) {

       if (action.id == "restartWifi" )

       {

           return polkit.Result.YES;

           }

   });

```

but it doesn't workLast edited by skorefish on Thu Jan 11, 2018 11:03 pm; edited 2 times in total

----------

## charles17

The question is: Why would you want to do that?

----------

## skorefish

 *Quote:*   

> charles17:The question is: Why would you want to do that?

 

for my .bash_profile to execute

```
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

----------

## krinn

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.

```
#!/bin/bash

while [ ! -f /tmp/whatevername ]

 do

 sleep 1

 done

/etc/init.d/net.wlp2s0 restart
```

and your .bash_profile adapt to

```
  then

        touch /tmp/whatevername

        startxfce4 --with-ck-launch

```

----------

## mv

 *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.

----------

## skorefish

 *Quote:*   

> you could start a script that loop for a file when you boot, 

 

very interesting method !!

and 

```
david asus=(ALL) NOPASSWD:/etc/init.d/net.wlp2s0,/etc/sudoers,/sbin/shutdown,/usr/bin/cpupower
```

works,but what about just typing 

```
/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?

----------

## Hu

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?

----------

