Minimizing password re-entry across terminal sessions for sudo

Warning: This is not something you should do in environments that care about security a lot – the default settings that do not allow this behavior is more secure and you should stick with that in such cases.

In my home network, one annoyance is executing a command as root using sudo (my setup is password less login as a regular user and use sudo for anything that requires root permissions) on a remote machine only to realize having to do something else quickly again – in a SSH or context with a terminal associated session, sudo has a default of not asking for the password again within 5 minutes (also configurable). But if you closed the ssh session or you are executing through automation where each invocation is a new terminal, this 5 minute no password doesn’t apply by default – instead you will be prompted for the password again immediately.

Turns out this behavior is also configurable – you can add a /etc/sudoers.d/user-sudo file with the following:

Defaults:<username> !tty_tickets

This allows the timeout to be applied across terminal sessions for the user.

Leave a Reply

Your email address will not be published. Required fields are marked *