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的更多相关文章

  1. -bash: sudo: command not found Error and Solution

    文章转自: http://www.cyberciti.biz/faq/debian-ubuntu-rhel-centos-linux-bash-sudo-command-not-found/ 安装su ...

  2. Linux:SSH错误"WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! "

    hadoop@master:~$ scp /home/hadoop/.ssh/authorized_keys node3:/home/hadoop/.ssh/ @@@@@@@@@@@@@@@@@@@@ ...

  3. Netbeans and Remote Host for C/C++ Developing

    Netbeans and Remote Host for C/C++ Developing 很久以来,因为我不适应在 Linux 下使用 Vim, GCC, GDB 开发 C/C++ 程序,所以我一直 ...

  4. SSH登录警告(WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!)

    在配置本机与docker容器实现ssh无密码访问时出现以下报错 # federico @ linux in ~ [18:35:52] C:127$ sudo ssh-copy-id -i .ssh/i ...

  5. Bind 远程连接DNS服务器时出现 rndc: connection to remote host closed

    使用命令:rndc -s 192.168.1.2 status 连接远程的bind 搭建的DNS服务器时出现下面的错误:   rndc: connection to remote host close ...

  6. what codes does sudo command do in Linux?

    sometime, to make your change of configuration file be effective to web application, we have to rest ...

  7. telnet报“Unable to connect to remote host:Connection refused”错误

    Linux下面telnet ip 端口号 报错误"Unable to connect to remote host:Connection refused"的时候,大部分是目标机的端 ...

  8. WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED

    原文地址:http://linuxme.blog.51cto.com/1850814/375752 今天将阿里云服务器更换了一下系统盘,重启成功后,再次通过终端访问阿里云的公网IP报以下信息: @@@ ...

  9. WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED解决方法

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@    WARNING: REMOTE HOST IDENTIFICATION ...

随机推荐

  1. ubuntu下mysql源码编译安装

    建议:cpu4核以上,内存4G以上 1. 安装环境:Ubuntu Server 14.10MySQL-5.6.23.tar.gz 2. 安装必备的工具sudo apt-get install make ...

  2. java工程师基础笔试题(一)-参考答案

    一.选择和填空  (不定项哦!) 1,如下是一份文件名为Test2.java的源文件,请问,编译该文件之后会生成几份字节码文件 class Test{ class Inner{} static cla ...

  3. Java方法的重载和重写

    重载与重写对比:  重载: 权限修饰符(public private 默认):无关 方法名:重载的两个方法的方法名必须相同 形参的个数不同 形参的类型不同 三者至少满足一个 返回值类型: 重载与返回值 ...

  4. oracle学习--循环语句

    oracle学习--循环语句  loop循环: create or replace procedure pro_test_loop is i number; begin i:=0; loop i:=i ...

  5. javascript基础:函数参数与闭包问题

    今天在写东西的时候,对函数参数的概念有些模糊,查阅相关资料后,在博客上记点笔记,方便日后复习. 首先,在js中函数参数并没有强语言中那么要求严格,他不介意传递进来多少个参数,也不在乎传进来的参数是什么 ...

  6. VS2013 warning C4018 "<” 有符号/无符号不匹配

    1, VS2013 warning C4018 "<” 有符号/无符号不匹配" 警告 出错代码: void show(const vector<int>& ...

  7. centos 配置Openssl并创建证书

    具体详情参考:http://wiki.centos.org/HowTos/Https 一.安装软件 yum install mod_ssl openssl 二.创建证书: # Generate pri ...

  8. WEB 自动化思路

    前期做了一个关键字驱动模型的WEB自动化项目,特意写文章归纳和总结下. 框架架构图 已经实现的部分: 1. 读写excel数据模板 2.配置中心,支持properties,xml格式的配置文件 3.参 ...

  9. 转移动APP测试实践

    http://blog.csdn.net/hgstclyh/article/details/53115325

  10. 一个先进的App框架:使用Ionic创建一个简单的APP

    原文  http://www.w3cplus.com/mobile/building-simple-app-using-ionic-advanced-html5-mobile-app-framewor ...