在使用sudo命令时如何不用输入密码或减少输入的次数?
方法1、sudo ./script.sh
但要输入第一次的密码
方法2、
echo password|sudo -S apt-get update-S的意思是,讲密码从standard input中读入
特别适合用于脚本。比如服务器的定期更新,当然你也可以直接用sudo用户,不过不安全
方法3、
In new /etc/sudoers.d/apt-get file, put single line:user ALL=(ALL:ALL) NOPASSWD:/usr/bin/apt-get update
Fully qualified path to executable is required here.
Then use following in your script:
sudo apt-get update
Here, fully specified name is not required. Sudo uses PATH environment variable for executable resolution.
While changing and checking sudoers configuration, be sure to keep another root session open for error recovery.
未尝试
本文介绍三种减少使用sudo命令时输入密码次数的方法:通过脚本传递密码、配置特定命令免密码执行及修改sudoers文件实现免密码运行指定命令。
599

被折叠的 条评论
为什么被折叠?



