zoukankan      html  css  js  c++  java
  • How to execute sudo command in remote host via SSH

    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'
    
     
     
  • 相关阅读:
    Java方法
    Java程序控制
    Java基础语法
    编程语言的两大类型
    IntelliJ IDEA优化配置
    Hello World
    Java安装及卸载
    Java来龙去脉
    计算机底层基础
    Day14
  • 原文地址:https://www.cnblogs.com/mouseleo/p/9808261.html
Copyright © 2011-2022 走看看