5

设置sudo的超时时间

 3 years ago
source link: https://www.lujun9972.win/blog/2018/09/10/%E8%AE%BE%E7%BD%AEsudo%E7%9A%84%E8%B6%85%E6%97%B6%E6%97%B6%E9%97%B4/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

设置sudo的超时时间

默认情况下sudo的超时时间为15分钟,也就是说,在上一个sudo命令后的15分种内是不需要重复输入密码的,而15分钟后则需要重复输入密码。

设置sudo的超时时间

要设置sudo的超时时间,只需要在 /etc/sudoers 中的 Defaults specification 中指定 timestamp_timeout=N 就可以了

这里 N 的单位为分钟,比如下面配置设置超时时间为10分钟

Defaults timestamp_timeout=10

这里需要说明的是

  • 若设置 N 为0,则表示每次sudo都必然要输入密码
  • 若设置 N 小于0,则sudo命令会执行失败

设置下一次sudo需要输入密码

若确定自己已经完成sudo操作,则可以执行 sudo -k 命令。

该命令会立即让用户的认证缓存无效,从而保证下次输入 sudo 命令必须输入密码

输入密码太麻烦?

如果觉得老是输入密码太麻烦,可以输入 sudo -s,这样你会发现以 root 用户的身份进入一个新shell中。

操作完之后,只需要输入 exit 退出该shell就可以了。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK