Have tmux not ask for sudo password for a process in session (authenticate beforehand)

sudotmux

I have already seen [SOLVED] Why sudo asks for user password in tmux/ssh session? ยท GitHub Gist, and it looks like this is there by design, but I thought I'd ask anyways:

Say I use a command like this:

tmux new-session -d 'sudo udevadm monitor -e' \; attach

As soon as tmux starts the new session, it asks for the sudo password, as expected. But then I try to "cheat" by attempting to validate sudo beforehand:

$ sudo --validate
[sudo] password for user:
$ tmux new-session -d 'sudo udevadm monitor -e' \; attach

… and this asks again for a sudo password as soon as tmux starts the session – even if I already entered the password successfully beforehand.

So is there a way to start a tmux session with (a) sudo'ed process(es) inside, with only one sudo password validation beforehand?

Best Answer

The simplest solution, if you can modify /etc/sudoers, is to unset the tty_tickets option for your user:

Defaults:yourlogin !tty_tickets

Then you can run a sudo command before running tmux, and sudo will update your (single) timestamp and allow the subsequent sudo commands without a password prompt (within the timestamp_timeout).

This is the pertinent option because, typically, the tty_tickets option is set, which requires a password for each tty and tmux starts a new tty.

Related Question