如何在Bash中消除“无法访问tty(坏文件描述符)”消息?

3

我有一个bash脚本,在其中使用ssh连接到另一台服务器并在那里运行一些命令。我发现一些网站上会出现错误信息(Warning: no access to tty (Bad file descriptor). Thus no job control in this shell.),这是一个友好的提示,但我的bash脚本卡住了。这条消息出现后,没有其他命令被执行。其他论坛建议使用ssh -t来抑制消息,但这对我不起作用。我的代码看起来像这样:

.
.
.
stty -echo
sshpass "pwd" ssh -o StrictHostKeyChecking=no usr@1.1.1.1 'su -lc "rm -rf tmp"' 2>/dev/null
stty echo
.
.
.

我使用 stty-echo 的原因是因为我需要切换用户到root,而密码会在终端上显示出来(这是我不想要的)。当我在连接服务器(ip: 1.1.1.1)上输入root密码后,我会收到错误信息 (Warning: no access to tty (Bad file descriptor). Thus no job control in this shell.)。

有什么建议吗?如果需要进一步解释,请告诉我。谢谢! (我的bash版本是GNU bash version 3.2.51(1))

编辑

当删除 2>/dev/null 时,我收到的错误消息是:

Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell. 
stty: standard input: Invalid argument

使用“-t”选项会消除该消息吗? - arco444
@arco444 已经尝试过了,但问题仍未解决。 - Redson
1个回答

1

与其试图隐藏密码,我建议您通过将您的ssh公钥添加到目标id/服务器来使ssh连接无需密码。您必须为您的密钥设置一个密码短语,并在需要时使用ssh-agent提供它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接