我想运行一个需要 sudo 密码的命令说:
sudo apt-get update
Run Code Online (Sandbox Code Playgroud)
这不是应该工作吗(我已将密码存储在普通文本文件中passwd.txt
):
sudo apt-get update <~/passwd.txt
Run Code Online (Sandbox Code Playgroud)
这是我为什么它应该工作的逻辑:当需要密码时,要求用户从键盘输入密码。但是重定向stdin
到从passwd.txt
文件中读取应该可以工作。
不应该吗?
Eri*_*lho 30
sudo
stdin
默认情况下不读取密码。从sudo
联机帮助页:
-S The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.
The password must be followed by a newline character.
Run Code Online (Sandbox Code Playgroud)
所以你应该运行:
sudo -S apt-get update <~/passwd.txt
Run Code Online (Sandbox Code Playgroud)
请记住,将密码存储在文件中不是一个好习惯。你应该阅读:
归档时间: |
|
查看次数: |
11210 次 |
最近记录: |