错误:“您必须有 tty 才能运行 sudo”使用 sshpass 时
我有 gitlab CI 作业,其脚本执行如下:
stage: permissions
script:
sshpass -p "${PASSWORD}" ssh ${USER}@${HOST} sudo chown -cv user_a:user_a ${directory}/test.txt
上面给出了以下错误:
sudo: sorry, you must have a tty to run sudo
如果我添加 -t
和 ssh
我得到:
Pseudo-terminal will not be allocated because stdin is not a terminal.
sudo: sorry, you must have a tty to run sudo
如果我添加 -tt
与ssh
,作业一直等待我输入密码。
我的要求是使用 ssh 和文本密码(即 sshpass )执行远程命令,有没有办法可以在不更改服务器上的任何 sudoers 权限的情况下实现此目的?
I have gitlab CI job which had a script execution like below:
stage: permissions
script:
sshpass -p "${PASSWORD}" ssh ${USER}@${HOST} sudo chown -cv user_a:user_a ${directory}/test.txt
The above gives me following error:
sudo: sorry, you must have a tty to run sudo
If i add -t
with ssh
i get:
Pseudo-terminal will not be allocated because stdin is not a terminal.
sudo: sorry, you must have a tty to run sudo
If i add -tt
with ssh
, the job keeps waiting for me to enter the password.
My requirement is to execute a remote command using ssh
and text password i.e. sshpass
, is there a way i can achieve this without change any sudoers permissions over the server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用类似的内容:
将密码从 not tty 写入 sudo 的示例:
ps 对于配置服务器,请使用 Ansible,他处理这样的任务非常容易。
Use somethinc like:
Example for write password from not tty to sudo:
p.s. For configure servers use Ansible, he handles such tasks very easily.