I tried to set up key bindings for changing the virtual terminal (VT) in X, as described in this post. Typing sudo chvt $(($XDG_VTNR-1)) into a terminal emulator appropriately changes the VT. However, I find that running chvt with elevated privileges works only when executed as a command to a terminal emulator (e.g., xterm -e), a requirement that I am trying to circumvent.
To describe my setup:
The following line was added to /etc/sudoers:
me ALL=NOPASSWD:/bin/chvt
where me is the output of whoami. I also tried variations on this line (e.g., me ALL=(ALL) NOPASSWD:/bin/chvt and me ALL=(ALL:ALL) NOPASSWD:/bin/chvt)
To ~/.xbindkeysrc, I added key bindings, either:
"sudo chvt $(($XDG_VTNR-1))"
alt + c:113
"sudo chvt $(($XDG_VTNR+1))"
alt + c:114
or
"sudo chvt $(($XDG_VTNR-1))"
m:0x8 + c:113
"sudo chvt $(($XDG_VTNR+1))"
m:0x8 + c:114
The first was suggested by the author of the linked post and the latter was determined by running xbindkeys -k on my system.
The key bindings failed and I ran xbindkeys in non-daemon mode to investigate. Pressing Alt+left or Alt+right while running xbindkeys -n gives the following error:
sudo: no tty present and no askpass program specified
Changing the command in ~/.xbindkeysrc to xterm -e sudo chvt ... produces a working key binding (but at the cost of opening an xterm instance and prompting for a password), which confirms that the lack of a tty is the issue. How can the invocation of sudo in .xbindkeys be achieved without first summoning a terminal?
System details: debian v9.2., dwm v6.1, openbox v.3.6.1, xbindkeys v1.8.6, sudo v1.8.19p1