AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 643142
Accepted
daltonfury42
daltonfury42
Asked: 2015-07-02 04:57:50 +0800 CST2015-07-02 04:57:50 +0800 CST 2015-07-02 04:57:50 +0800 CST

是否可以只输入一次 sudo 密码,并将其配置为在其他终端上不需要密码?

  • 772

我输入我的第一个sudo命令。我输入我的密码。有一段时间,我不必为后续的 sudo 命令输入密码。

现在的问题。我是一个打开很多终端的人。如果我在第一个 sudo 后打开的终端中使用时不必输入密码,那将非常方便sudo,因为在短时间内我不必在我使用 sudo 的终端中输入 sudo 的密码第一次。(对不起,句子太长了!)

可能吗?如果不是,为什么?如果是,如何?

command-line
  • 3 3 个回答
  • 11893 Views

3 个回答

  • Voted
  1. Best Answer
    terdon
    2015-07-02T05:03:23+08:002015-07-02T05:03:23+08:00

    是的。运行sudo visudo并将此行添加到您的sudoers文件中:

    Defaults        !tty_tickets
    

    如中所述man sudoers:

     tty_tickets       If set, users must authenticate on a per-tty basis.
                       With this flag enabled, sudo will use a separate record
                       in the time stamp file for each tty.  If disabled, a
                       single record is used for all login sessions.  This
                       flag is on by default.
    

    通过设置tty_tickets为关闭(就是这个!意思),您可以启用单个身份验证以由多个会话共享。

    • 62
  2. Theodore R. Smith
    2020-10-01T08:51:02+08:002020-10-01T08:51:02+08:00

    所以这里是你想要做的,每次启动时只让 sudo 询问你的密码一次:

    /etc/sudoers.d/00_prompt_once:

    ## Only ask for the password once for all TTYs per reboot.
    ## See https://askubuntu.com/a/1278937/367284 and
    ##     https://github.com/hopeseekr/BashScripts/
    Defaults !tty_tickets
    Defaults timestamp_timeout = -1
    
    • 0
  3. Alexander McConaughey
    2022-03-15T11:30:48+08:002022-03-15T11:30:48+08:00

    在你的 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.
    
    • 0

相关问题

  • 如何从命令行仅安装安全更新?关于如何管理更新的一些提示

  • 如何从命令行刻录双层 dvd iso

  • 如何从命令行判断机器是否需要重新启动?

  • 文件权限如何工作?文件权限用户和组

  • 如何在 Vim 中启用全彩支持?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve