Command-Line – How to Make Super-User Permissions Last Longer Than Using Sudo

command linepasswordpermissionssudo

Is there a way through which I can make the sudo command give me permissions for a longer period than its default time?

It can be a pain having to keep entering the sudo password, when requiring the installation of many packages, so it would be nice if there exists a command or configuration that can be done to affect it usage period.

Best Answer

Behavior of sudo is configured in /etc/sudoers file. There is timestamp_timeout option responsible for reprompting the user for password after specific amount of time.

From man sudoers

timestamp_timeout
                       Number of minutes that can elapse before sudo will ask
                       for a passwd again.  The timeout may include a frac‐
                       tional component if minute granularity is insufficient,
                       for example 2.5.  The default is 15.  Set this to 0 to
                       always prompt for a password.  If set to a value less
                       than 0 the user's time stamp will never expire.

To alter that setting do the following:

  1. In terminal run sudo visudo. visudo is used specifically to edit /etc/sudoers file and by default uses nano text editor.
  2. Find the lines starting with Defaults. Add the following line

    Defaults        timestamp_timeout=x
    

    where x is the amount of minutes you want between reprompts

  3. Save the file with Ctrl + O

Related Question