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. EasyUI值的清空与获取

    清空: 一般值 $("#searchx").val(""); 时间选择框 $('#starttime').datetimebox('setValue', '') ...

  2. unity延时方法

    http://www.cnblogs.com/louissong/p/3832960.html 借鉴上面的博客中的内容: Invoke(methodName: string, time: float) ...

  3. Appium 连手机失败Error: Android bootstrap socket crashed: Error: getaddrinfo ENOTFOUND localhost undefined:4724

    问题:Appium执行,连接手机报下面的错误 Error: Android bootstrap socket crashed: Error: getaddrinfo ENOTFOUND localho ...

  4. Excel学习之图表创建

    前言:由于工作的需要,现在需要恶补Excel知识,温故而知新,不记录下来自己的学习的点点滴滴怎么能行 Excel版本:2016 一.插入如下图所示的数据源: 1.勾选图表区域范围 2.选中区域范围后直 ...

  5. eclipse启动tomcat后,无法通过路径访问项目

    eclipse已启动,访问localhost:8080也出现了tomcat页面,但是无法通过项目路径去访问项目,解决办法: 在控制台区域打开tomcat server,默认是第一项,且无法修改: 先把 ...

  6. if (HttpContext.Current.User.Identity.IsAuthenticated) 权限验证总是true

    将浏览器关闭重启. 注:该语句是判断用户是否经过验证.

  7. Python常用库大全,看看有没有你需要的

    作者:史豹链接:https://www.zhihu.com/question/20501628/answer/223340838来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  8. expect命令自动登录ssh

    expect是简单的工具原因,依赖于tcl. 直接apt安装就行. 四个关键字: spawn,派生出新进程. expect,期待得到的字符串,可以模式匹配. send,向进程发送字符串. intera ...

  9. 牛客网 Wannafly挑战赛12 删除子串(线性dp)

    题目描述 给你一个长度为n且由a和b组成的字符串,你可以删除其中任意的部分(可以不删),使得删除后的子串“变化”次数小于等于m次且最长. 变化:如果a[i]!=a[i+1]则为一次变化.(且新的字符串 ...

  10. Django2.0的path方法无法使用正则表达式的解决办法

    本人的django的版本是2.0.6 在django项目中,在urls.py文件中,匹配路由用的path方法,之前我用的都是url方法 写了一个path方法,使用正则表达式 from django.c ...