加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

在here-document中通过SSH运行命令时不存在TTY

发布时间:2020-12-13 18:18:59 所属栏目:Linux 来源:网络整理
导读:我正在尝试通过这样的文档在这样的SSH上运行命令: ssh example.com ENDsudo /etc/init.d/apache2 reloadEND 除非我正在尝试运行需要输入的内容,例如sudo的密码,否则通常可以正常工作.在这种情况下,我收到以下消息: sudo: no tty present and no askpass pr
我正在尝试通过这样的文档在这样的SSH上运行命令:
ssh example.com <<END
sudo /etc/init.d/apache2 reload
END

除非我正在尝试运行需要输入的内容,例如sudo的密码,否则通常可以正常工作.在这种情况下,我收到以下消息:

sudo: no tty present and no askpass program specified

我知道我可以在SSH上使用-t标志来分配伪tty,例如:

ssh -t example.com "sudo /etc/init.d/apache2 reload"

它会工作,但是当我在这里尝试同样的事情 – 文档时,它不起作用,我将得到关于没有tty存在的相同错误:

ssh -t example.com <<END
sudo /etc/init.d/apache2 reload
END

知道如何让这个工作吗?

另外,如果你想知道为什么我希望它使用here-document而不是只是在同一行上传递它,那是因为输入命令(可能有几个)来自脚本读取的配置文件而且我听说它避免了转义引号,双引号等命令的麻烦.

解决方法

使用visudo编辑sudoers文件并插入以下行:
Defaults:<user>    !requiretty

It doesn’t answer why using the ssh -t "something" versus ssh -t
<<STOP something STOP
doesn’t work. Let’s say I’m not using sudo but
I’m using passwd for my own user directly,I still won’t get the TTY
using the heredoc.

尝试ssh -t -t强制伪tty分配,即使stdin不是终端.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读