如何更改sudo再次提示之前的等待时间

00_lead_image_sudo_password_prompt

When you use the sudo command to run commands as root or administrator you are prompted to enter your password. You may have noticed that if you run another command using sudo shortly after the first command, you are not prompted for your password again.

当您使用sudo命令以root或管理员身份运行命令时,系统会提示您输入密码。 您可能已经注意到,如果在第一个命令之后不久使用sudo运行另一个命令,则不会再次提示您输入密码。

You can customize the length of that grace period in which you are not asked to enter your password for the sudo command again by changing a setting for the sudo command.

您可以通过更改sudo命令的设置来定制宽限期的长度,在该宽限期内,系统不会要求您再次输入sudo命令的密码。

NOTE: When we say to type something in this article and there are quotes around the text, DO NOT type the quotes, unless we specify otherwise.

注意:当我们说要在本文中键入某些内容并且文本周围有引号时,请不要键入引号,除非我们另外指定。

We will open the “/etc/sudoers” file and change a setting to customize the length of the grace period. To begin, press Ctrl + Alt + T to open a Terminal window. Type the following command at the prompt and press Enter.

我们将打开“ / etc / sudoers”文件并更改设置以自定义宽限期的长度。 首先,请按Ctrl + Alt + T打开“终端”窗口。 在提示符下键入以下命令,然后按Enter。

sudo visudo

苏多维苏多

Type your password when prompted and press Enter.

出现提示时输入密码,然后按Enter。

01_opening_visudo_file

A file opens directly in the Terminal window using the Nano text editor. Use the arrow keys on your keyboard to move the cursor to the end of the following line:

使用Nano文本编辑器直接在“终端”窗口中打开一个文件。 使用键盘上的箭头键将光标移至以下行的末尾:

Defaults         env_reset

默认值env_reset

IMPORTANT: Never edit the sudoers file with a normal text editor. Always use the visudo command as described here. If the sudoers file has improper syntax, you will be left with a system where it’s impossible to obtain elevated or root privileges. The visudo command opens a text editor like you would with normal text files, but the command also validates the syntax of the file upon saving it. This prevents configuration errors in the sudoers file from blocking sudo operations, and you will lose what could be your only method of obtaining root privileges.

重要说明:切勿使用常规文本编辑器编辑sudoers文件。 始终按此处所述使用visudo命令。 如果sudoers文件的语法不正确,您将获得无法获得提升特权或root特权的系统。 visudo命令像打开普通文本文件一样打开文本编辑器,但是该命令还会在保存文件时验证文件的语法。 这样可以防止sudoers文件中的配置错误阻止sudo操作,并且您将失去获得根特权的唯一方法。

Traditionally, Linux uses vi as the default editor, but Ubuntu has chosen to use Nano. If you would rather use vi as the default text editor in Ubuntu, rather than Nano, see our article.

传统上,Linux使用vi作为默认编辑器,但是Ubuntu选择使用Nano。 如果您希望使用vi作为Ubuntu中的默认文本编辑器,而不是Nano,请参阅我们的文章

02_env_reset_line_original

Change the line by adding “, timestamp_timeout=x” to the end of the line.

通过在行末添加“,timestamp_timeout = x”来更改行。

Defaults                 env_reset, timestamp_timeout=x

默认值env_reset,timestamp_timeout = x

Replace “x” with the number of minutes you want sudo to wait in the same Terminal session before prompting you to enter your password again.

将“ x”替换为您希望sudo在同一终端会话中等待的分钟数,然后提示您再次输入密码。

If you enter “-1” for “x,” the password prompt is revoked. This is not recommended. If you want the system to prompt you for a password every time you use the sudo command, enter “0” for “x.”

如果为“ x”输入“ -1”,则密码提示将被撤消。 不建议这样做。 如果希望系统在每次使用sudo命令时提示您输入密码,请在“ x”中输入“ 0”。

03_env_reset_line_revised

Once you have made the change, press Ctrl + X and type a “y” in response to the question that displays at the bottom of the window to save your changes.

进行更改后,按Ctrl + X并键入“ y”,以回答显示在窗口底部的问题以保存更改。

04_saving_and_exiting

You will be asked for the File Name to Write at the bottom. Press Enter to accept the default.

在底部将要求您输入要写入的文件名。 按Enter接受默认值。

05_file_name_to_write

You are returned to the command prompt. To close the Terminal window, type “exit” at the prompt and press Enter. You can also click the X button in the upper-left corner of the window.

您将返回到命令提示符。 要关闭“终端”窗口,请在提示符下键入“ exit”,然后按Enter。 您也可以单击窗口左上角的X按钮。

06_closing_terminal

You can also clear the password cache for sudo by typing the following command at the prompt and pressing Enter.

您还可以通过在提示符下键入以下命令并按Enter来清除sudo的密码缓存。

sudo –k

须藤–k

This will cause the password prompt to display again when using sudo even if the entire grace period has not passed.

即使未经过整个宽限期,使用sudo时,这也会导致密码提示再次显示。

翻译自: https://www.howtogeek.com/193811/how-to-change-how-long-sudo-waits-before-it-prompts-you-again/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值