【FAQ】How to run sudo command without typing passwd?

转载 2015年11月18日 16:36:36

From : http://www.ducea.com/2006/06/18/linux-tips-password-usage-in-sudo-passwd-nopasswd/

If you are using sudo you most certainly know that the default setup will require the user running sudo to enter a password (by default the password of the user running sudo). I will show you in this post what options sudo offers related to passwords and how they can be used.


If you have an entry in your sudoers file that contains something like this:

admin    ALL=(ALL) ALL

then sudo will require you to enter a password when running a command with sudo. This is theuser password (and not the root password), in this case the password of the user “admin”.


If for some reason you want to change this behavior, then you can use the sudo global flagtargetpw. This is by default OFF, and if you set it like show bellow then the password you will be asked while running sudo will be the password of the target user (in our case the root password).

Defaults    targetpw

Personally, I don’t see the use of this parameter and never used it myself… But maybe someone else will find it useful.


If you don’t want to be prompted for any password while running sudo then we can use theNOPASSWD parameter on a particular entry:

admin    ALL = NOPASSWD: ALL

this parameter is the opposite of the default PASSWD and will no longer require any password for the user “admin” while running sudo. This can be of useful while running scripts that will launch sudo (in this case I would recommend to enable NOPASSWD only for the needed commands), or just if you don’t want to keep typing the password. Obviously with this commodity, you will reduce the security of sudo: if someone hacks the “admin” account then this can be easily used to gain root privileges.


Another sudo option that can be used to control the prompt for a password is the global flag:authenticate. This is by default ON and this means that it will ask the user to authenticate with a password. This can be overwritten as seen above with the NOPASSWD on a particular entry. If we want to disable it globally, this can be done with:

Defaults    !authenticate

Once set, this will disable authentication for all users that use the defaults like our “admin” sample from above. It can be overwritten on particular definition by setting the PASSWDparameter:

admin    ALL=(ALL) PASSWD: ALL

Note: this post doesn’t recommend you to disable the passwords usage in sudo (this is not a good idea, by the way), but just to show you what options are available and how you can use them. Knowing the security implications of disabling password usage in sudo, use them wisely based on your particular needs.


UID 0 系统管理员 1~499 系统账号(/sbin/nologin; 1-99 属于各个distributions创建,100~499用户自行创建的系统账号) 500~65535 一般账号...
  • elihe2011
  • elihe2011
  • 2016年03月15日 21:37
  • 242


1. 创建一个Dockerfile文件 FROM centos:6.7 MAINTAINER Yong Zhang ##########################################...
  • mesos
  • mesos
  • 2016年04月19日 14:17
  • 261

如何免 sudo 使用 docker

1 简介 默认安装完 docker 后,每次执行 docker 都需要运行 sudo 命令,非常浪费时间影响效率。如果不跟 sudo,直接执行 docker images 命令会有如下问题: ...
  • genghaihua
  • genghaihua
  • 2015年11月14日 21:07
  • 1927

smbpasswd: command not found

#解决: yum install samba-client
  • github_26672553
  • github_26672553
  • 2015年05月14日 15:36
  • 1224

root下command not found的解决以及su root密码不正确的解决

给和我一样的小白…… 问题描述: 我在terminal中输入sudo -s切换到root,发现ifconfig,service,chkconfig这三个命令都提示command not f...
  • yunixiang
  • yunixiang
  • 2015年03月12日 10:07
  • 2866

Ubuntu terminal一直提示使用sudo 执行命令

每次打开Terminal, 窗口上方都会出现 To run a command as administrator (user "root"), use "sudo ". See "man sudo...
  • lxbwolf
  • lxbwolf
  • 2016年12月10日 12:48
  • 1211

hdu How to Type (dp)

How to Type Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) T...
  • Wiking__acm
  • Wiking__acm
  • 2012年08月14日 12:47
  • 1155

How to run a .BAT file in InstallShield?

InstallShield做的安装包可以执行exe、vbs脚本、js脚本,就是不能执行bat??找这个答案半天。 终于在官方论坛找到了比较perfect的答案。cmd.exe /c batfilena...
  • cyatzzu
  • cyatzzu
  • 2007年09月18日 18:13
  • 2628

ubuntu 下sudo cd 会报command not found

ubuntu 下sudo cd 会报command not found 参考:http://linuxcommando.blogspot.com/2007/11/sudo-hacks-makin...
  • ghj1976
  • ghj1976
  • 2010年12月09日 17:03
  • 14571

ubuntu修改root密码,$ sudo passwd root

lyzh@ubuntu:~$ passwd root passwd: You may not view or modify password information for root. lyzh@ub...
  • u010002184
  • u010002184
  • 2016年10月31日 19:55
  • 4826
您举报文章:【FAQ】How to run sudo command without typing passwd?