You are not logged in.

#1 2019-12-15 22:10:52

AliReza
Member
Registered: 2019-12-10
Posts: 9

[SOLVED] Restarting a service with a keybind in i3

Hi, I want to use $mod+t keybind to restart tor service
I tried this in my config:

bindsym $mod+t exec systemctl restart tor.service

but it doesn't work (because it needs root permission)
I also tried to use sudo but it doesn't work too(because it wants me to enter my password and that's not possible when I'm use a keybind)

Last edited by AliReza (2019-12-16 15:54:59)

Offline

#2 2019-12-15 22:15:59

dglt
Member
Registered: 2019-08-14
Posts: 82

Re: [SOLVED] Restarting a service with a keybind in i3

you can try this, it should prompt for a password rather than fail to work.

pkexec systemctl restart tor.service

Offline

#3 2019-12-16 10:11:18

AliReza
Member
Registered: 2019-12-10
Posts: 9

Re: [SOLVED] Restarting a service with a keybind in i3

That doesn't work, pkexec asks for password in command line but I want to use it without command line (by pressing $mod+t)

I tried:

bindsym $mod+t exec pkexec systemctl restart tor.service

Last edited by AliReza (2019-12-16 10:13:40)

Offline

#4 2019-12-16 10:23:48

Skunky
Member
Registered: 2018-01-25
Posts: 231

Re: [SOLVED] Restarting a service with a keybind in i3

You could make your terminal emulator ask for password e.g.

 termite -e "systemctl restart tor.service" 

Otherwise you could disable password prompts completely, see visudo

Last edited by Skunky (2019-12-16 10:28:40)

Offline

#5 2019-12-16 10:24:10

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] Restarting a service with a keybind in i3

Add the relevant line to sudoers...
https://wiki.archlinux.org/index.php/Sudo


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#6 2019-12-16 15:51:59

AliReza
Member
Registered: 2019-12-10
Posts: 9

Re: [SOLVED] Restarting a service with a keybind in i3

Skunky wrote:

You could make your terminal emulator ask for password e.g.

 termite -e "systemctl restart tor.service" 

Otherwise you could disable password prompts completely, see visudo

That worked!
Thanks

Offline

#7 2019-12-16 15:54:22

AliReza
Member
Registered: 2019-12-10
Posts: 9

Re: [SOLVED] Restarting a service with a keybind in i3

Slithery wrote:

Add the relevant line to sudoers...
https://wiki.archlinux.org/index.php/Sudo

Thanks for your advise, but it I can't do this because of security reasons

Offline

#8 2019-12-16 15:58:02

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,371

Re: [SOLVED] Restarting a service with a keybind in i3

You could also install an actual polkit agent so that pkexec actually gives you a dialog: https://wiki.archlinux.org/index.php/Po … ion_agents

Online

#9 2019-12-16 17:05:41

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,517
Website

Re: [SOLVED] Restarting a service with a keybind in i3

AliReza wrote:

Thanks for your advise, but it I can't do this because of security reasons

What do you mean?  You want to be able to run this command without a password, don't you?  If not, what is your end goal?


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#10 2019-12-17 10:59:48

AliReza
Member
Registered: 2019-12-10
Posts: 9

Re: [SOLVED] Restarting a service with a keybind in i3

Trilby wrote:
AliReza wrote:

Thanks for your advise, but it I can't do this because of security reasons

What do you mean?  You want to be able to run this command without a password, don't you?  If not, what is your end goal?

Yes, but I don't want to turn off password asking for sudo command!

Last edited by AliReza (2019-12-17 11:00:25)

Offline

#11 2019-12-17 11:04:16

AliReza
Member
Registered: 2019-12-10
Posts: 9

Re: [SOLVED] Restarting a service with a keybind in i3

V1del wrote:

You could also install an actual polkit agent so that pkexec actually gives you a dialog: https://wiki.archlinux.org/index.php/Po … ion_agents

Thanks, I would try it

Last edited by AliReza (2019-12-17 11:04:47)

Offline

#12 2019-12-17 11:43:37

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] Restarting a service with a keybind in i3

AliReza wrote:
Trilby wrote:
AliReza wrote:

Thanks for your advise, but it I can't do this because of security reasons

What do you mean?  You want to be able to run this command without a password, don't you?  If not, what is your end goal?

Yes, but I don't want to turn off password asking for sudo command!

I wasn't suggesting that you allow any usage of sudo without a password - just that one specific command.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#13 2019-12-17 20:54:53

AliReza
Member
Registered: 2019-12-10
Posts: 9

Re: [SOLVED] Restarting a service with a keybind in i3

Slithery wrote:
AliReza wrote:
Trilby wrote:

What do you mean?  You want to be able to run this command without a password, don't you?  If not, what is your end goal?

Yes, but I don't want to turn off password asking for sudo command!

I wasn't suggesting that you allow any usage of sudo without a password - just that one specific command.

How can I do that?

Offline

#14 2019-12-17 20:59:47

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] Restarting a service with a keybind in i3

By reading the link I gave you in post #5...


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

Board footer

Powered by FluxBB