码迷,mamicode.com
首页 > 其他好文 > 详细

How to execute sudo command in remote host via SSH

时间:2018-10-18 10:46:55      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:ack   cat   shell   password   cut   cti   serve   comm   art   

Question:

I have an interactive shell script, that at one place needs to ssh to another machine (Ubuntu based) and execute something as root (the user should enter his password, but the remote command should run like noted in the script):

# ...
ssh remote-machine ‘sudo ls‘
# ...

However, I always get this error message back:

sudo: no tty present and no askpass program specified

OK, that‘s quite clear. But how can I circumvent this? Something like this should happen:

$ ssh remote-machine ‘sudo ls /‘
[sudo] password for user1:

/bin
/etc
/var

Answer:

The wondrous ssh has a cure for everything. The point is to add the -t flag to force ssh to allocate a pseudo-tty:

ssh -t remote-server ‘sudo ls‘
 
 

How to execute sudo command in remote host via SSH

标签:ack   cat   shell   password   cut   cti   serve   comm   art   

原文地址:https://www.cnblogs.com/mouseleo/p/9808261.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!