在您的sudoers.d文件中
sudo EDITOR=vim visudo -f /etc/sudoers/<filename>
添加以下内容:
Defaults timestamp_timeout=-1
man sudoers 揭示了以下内容:
sudoers uses per-user time stamp files for credential caching. ... The user may then use sudo without a password for a short period of time (15 minutes unless overridden by the timestamp_timeout option). ... The timestamp_type option can be used to select the type of time stamp record sudoers will use.
更进一步:
timestamp_timeout
Number of minutes that can elapse before sudo will ask for a passwd again. The timeout may include a fractional 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 not expire until the system is rebooted. This can be used to allow users to create or delete their own
time stamps via “sudo -v” and “sudo -k” respectively.