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

使用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"

posted on 2015-06-15 17:12  Tyoyi  阅读(547)  评论(0编辑  收藏  举报

导航