如何在不覆盖TTY的情况下将密码传递给su/sudo/ssh? [英] How to pass the password to su/sudo/ssh without overriding the TTY?

查看:115
本文介绍了如何在不覆盖TTY的情况下将密码传递给su/sudo/ssh?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个将执行susudossh的C Shell程序.他们都希望在控制台输入(TTY)中输入密码,而不是在stdin或命令行中输入密码.

I'm writing a C Shell program that will be doing su or sudo or ssh. They all want their passwords in console input (the TTY) rather than stdin or the command line.

有人知道解决方案吗?

不能设置无密码的sudo.

的问题可能是一种选择,但这是在精简版系统上不存在.

expect could be an option, but it's not present on my stripped-down system.

推荐答案

对于sudo,有一个-S选项,用于接受来自标准输入的密码.这是该人员的条目:

For sudo there is a -S option for accepting the password from standard input. Here is the man entry:

    -S          The -S (stdin) option causes sudo to read the password from
                the standard input instead of the terminal device.

这将允许您运行以下命令:

This will allow you to run a command like:

echo myPassword | sudo -S ls /tmp

至于ssh,我已经进行了很多尝试以自动化/脚本化其用法,但均未成功.在没有提示的情况下,似乎没有任何内置方法可以将密码传递到命令中.正如其他人提到的那样,"期望"实用程序似乎旨在解决这一难题,但最终,设置正确的私钥授权是尝试自动执行此操作的正确方法.

As for ssh, I have made many attempts to automate/script it's usage with no success. There doesn't seem to be any build-in way to pass the password into the command without prompting. As others have mentioned, the "expect" utility seems like it is aimed at addressing this dilemma but ultimately, setting up the correct private-key authorization is the correct way to go when attempting to automate this.

这篇关于如何在不覆盖TTY的情况下将密码传递给su/sudo/ssh?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆