欺骗从 shell 脚本中运行的程序,使其认为它正在从终端读取
我想编写一个 shell 脚本,执行如下所示的操作,
while read line; do
echo $line
done<input.txt | ssh > output.txt
目前这有点伪代码(原始版本正在工作),但您应该能够知道它在做什么。对于简单的应用程序来说,这很不错,但是 ssh 会检查输入以查看它的标准输入是否是终端。
有没有办法让 ssh 认为我的管道循环的内容是终端而不是管道?
编辑:抱歉最初没有添加此内容,这是为了允许 ssh 通过 shell 脚本登录(回答密码提示)
I'd like to write a shell script that does something like the following
while read line; do
echo $line
done<input.txt | ssh > output.txt
This is a bit pseudo codey at the moment (the original is at work), but you should be able to tell what it's doing. For simple applications this works a treat, but ssh checks the input to see whether it's stdin is a terminal.
Is there a way to fool ssh into thinking that the contents of my piped loop are a terminal rather than a pipe?
EDIT : Sorry for not adding this originally, this is intended to allow ssh to log in via the shell script (answering the password prompt)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ssh -t -t
将执行您想要的操作 - 这告诉 ssh 分配一个伪终端,无论它是否实际在其中运行。ssh -t -t
will do what you want - this tells ssh to allocate a pseudo terminal no matter whether it is actually running in one.更新
这个问题(在更新您的问题和各种评论后,很明显您正在寻找一种方便地实现公钥加密的方法)也许可以通过“颠倒思考”来解决。
您可以尝试从该服务器接收经过身份验证的身份(私钥),而不是努力将客户端公钥发送到尚未对客户端进行身份验证的服务器上。
简单来说:在服务器而不是客户端生成密钥对,然后想办法在客户端获取密钥对。服务器可以提前将公钥放入其authorized_keys中,以便客户端可以立即连接。
可能
原答案:
简短回答:不。 (这将是 ssh 的安全漏洞,因为 ssh “信任”tty 来输入密码,并且仅信任 tty)
长答案,您可以尝试颠覆/创造性地使用终端模拟器(查看 script/scriptreplay 以获得灵感)。
你为什么要这么做?
Update
This problem (after updating your question and various comments, it became clear you are looking for a way to conveniently get public key encryption into place) could perhaps be solved by 'thinking upside down'.
Instead of trying very hard to get your clients public key onto a server that doesn't yet authenticate the client, you can try to receive an authenticated identity (private key) from that server.
Simple terms: generate a keypair on the server instead of the client, and then find a way to get the keypair on the client. The server can put the public key in it's authorized_keys in advance, so the client can connect right away.
Chances are that
Original answer:
Short answer: Nope. (it would be a security hole for ssh, because ssh 'trusts' the tty for password entry, and the tty only)
Long answer, you could try to subvert/creatively use a terminal emulator (look at script/scriptreplay for inspiration).
Why would you want to do it?