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. MyBatis数据库连接的基本使用-补充Mapper映射器

    补充 Mapper映射器的使用: Mapper映射器,google添加.Mapper映射器是将mapper.xml中配置的sql id,parameterType和resultMap按照规则一一映射到 ...

  2. Win10 Fn键切换

    [Win10 Fn键切换] 选择 FN+ESC 参考:https://zhidao.baidu.com/question/626159613433698444.html

  3. CSS中的通用字体

    往往设计师在设计时一厢情愿地去思考问题,那样会带来很多潜在的麻烦.事实上你可以为网页设计任意字体,包括艺术字体.也许你的计算机中已经安装了很多字体,但是不能够保证所有的浏览者都已经安装了相同的字体,因 ...

  4. Oracle怎么修改字段类型

    转载:https://www.2cto.com/database/201710/689523.html 有一个表名为tb,字段段名为name,数据类型nchar(20). 1.假设字段数据为空,则不管 ...

  5. TCP和UDP协议的比较

    通信协议 网络通信是两台计算机上的两个进程之间的通信. 网络通信需要通信协议.网络协议有很多种,就像我们平常交流说话,也有多种语言.. 最常见的协议是TCP/IP协议.UDP协议. TCP:TCP 是 ...

  6. git和svn的对比

  7. 电商项目中学到的git命令

    1.在拉下来的文件夹被删除后的操作 创建了文件后 git init 增加了 .git文件 ls -al 查看后有.git文件夹 git remote add origin (ssh) 连接到git仓库 ...

  8. Jenkins安装部署(一)

    环境准备 CentOS Linux release 7.4 1.IP:192.168.43.129 2.路径:/mnt 3.jdk版本:jdk1.8.0 4.tomcat版本:tomcat-8.5 5 ...

  9. [Java学习]面向对象-类的继承;方法覆盖

    一.类的继承 实现方法: public Class SubClass extends SuperClass{ } 继承最基本作用: 代码重用. 继承最重要的作用: 方法可以重写. 关于类的继承: 子类 ...

  10. 1.尽量以const ,enum,inline替换define

    1.#define为预处理阶段命令 原因:有可能记号名称没有进入记号表,而出现编译错误,即编译器并没看到过该定义. class专属常量const 一般定义为static,保证该常量至多有一份实体. 枚 ...