我正在编写一个C Shell程序,它将执行su
、sudo
或ssh
.他们都希望自己的密码出现在控制台输入(TTY)中,而不是stdin或命令行中.
有人知道解决办法吗?
设置密码小于sudo
不是一个选项.
expect could be an option, but it's not present on my stripped-down system.
我正在编写一个C Shell程序,它将执行su
、sudo
或ssh
.他们都希望自己的密码出现在控制台输入(TTY)中,而不是stdin或命令行中.
有人知道解决办法吗?
设置密码小于sudo
不是一个选项.
expect could be an option, but it's not present on my stripped-down system.
对于sudo,有一个-S选项用于接受来自标准输入的密码.以下是男子入口:
-S The -S (stdin) option causes sudo to read the password from
the standard input instead of the terminal device.
这将允许您运行以下命令:
echo myPassword | sudo -S ls /tmp
至于ssh,我已经多次try 自动化/script,但都没有成功.似乎没有任何内置方式可以在没有提示的情况下将密码传递到命令中.正如其他人所提到的,"expect"实用程序似乎旨在解决这一难题,但最终,在try 实现自动化时,设置正确的私钥授权是正确的方法.