使用ssh进行无密访问,并发送执行命令的时候遇到了如题的错误

执行命令ssh user@host "sudo rm /data/test,txt"

sudo: sorry, you must have a tty to run sudo

查看资料发现

That's probably because your /etc/sudoers file (or any file it includes) has:

Defaults requiretty

也就是说sudo必须在一个TTY(输入输出设备)

解决方案:
在ssh中使用t 或者 tt命令,产生一个伪终端,并且再增加
stty raw -echo命令

最终命令更改如下:
ssh -tt user@host "stty raw -echo; sudo rm /data/test,txt"

相关文章:

  • 2021-09-28
  • 2021-10-22
  • 2021-06-07
  • 2021-09-04
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-20
  • 2021-10-15
  • 2022-03-02
  • 2021-10-02
  • 2021-06-15
  • 2022-01-10
相关资源
相似解决方案