设置 ubuntu sudo 时不用输密码

本文介绍如何在基于Ubuntu的系统中设置免密码使用sudo命令。通过编辑/etc/sudoers.d/目录下的文件,可以实现特定用户无需输入密码即可执行sudo命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


先提一下我的系统:LinuxMint 17 xfce 32-bits(基于 ubuntu 14.04 LTS)

ubuntu sudo 时输密码可烦人了,其实解决起来也不难,请看

我们先看看 sudo 的配置文件 $sudo cat /etc/sudoers

#

# This file MUST be edited with the 'visudo' command as root.

#

# Please consider adding local content in /etc/sudoers.d/ instead of

# directly modifying this file.

在注释中我们可以看到系统为了安全起见,不建议我们直接编辑这个配置文件(万一处理不好可能你就没法使用 sudo 了),而是编辑 /etc/sudoers.d/ 目录下的文件。好,我们就进入 /etc/sudoers.d/ 来看看 

$ ls

mintupdate README 

养成一个好习惯,先看 README ,

$sudo cat README 

#

# As of Debian version 1.7.2p1-1, the default /etc/sudoers file created on

# installation of the package now includes the directive:


#     #includedir /etc/sudoers.d


# This will cause sudo to read and parse any files in the /etc/sudoers.d

# directory that do not end in '~' or contain a '.' character.

#

# Note that there must be at least one file in the sudoers.d directory (this

# one will do), and all files in this directory should be mode 0440.

好了,此时你应该知道怎么做了吧,touch 一个文件 nopasswd4sudo,内容如下, 

yourusername ALL=(ALL) NOPASSWD: ALL 

完成之后,记得按要求 sudo chmod 0440 nopasswd4sudo 哦

更改完之后,sudo apt-get update 直接就更新了,说明sudo每次执行时都会先查看 /etc/sudoers.d/ 目录下的文件的 大笑

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值