默认状态下sudo执行命令之后的15分钟内再次使用sudo使用命令将不需要再次输入密码,在绝大多数情况下这个时间太短了。通过对sudoers文件的修改可以延长sudo密码的时限。
以下为man手册中对sudoers文件的描述:
The sudoers file is composed of two types of entries: aliases (basically variables) and user specifications (which specify who may run what).
When multiple entries match for a user, they are applied in order. Where there are multiple matches, the last match is used (which is not necessarily the most specific match).
The sudoers grammar will be described below in Extended Backus Naur Form (EBNF).Don’t despair if you don’t know what EBNF is; it is fairly simple, and the defi-nitions below are annotated.
要延长sudo的时限,只需要在/etc/sudoers任意位置添加一句:
Defaults:swift timestamp_timeout=0
其中的数字代表你希望sudo记录时间戳的长度。0为不记录。如果该值为-1则代表sudo永远记住该密码,直到重启。
sudoers文件中还有很多其他的选项可用于对sudo命令的相关进行配置。更详细的操作方法可以在man手册中查到。
—————————
P.S.如果觉得将timestamp_timeout设置为-1不安全,可以在执行命令后或者离开电脑时执行sudo -k停止当前的时间戳,下次执行sudo时会再次提示输入密码
如果你喜欢这篇日志的话,欢迎订阅我的RSS Feed!
本文来源于一阁Blog。版权所有,转载请确保已阅读该页面。


1 Response to “延长sudo密码时限”