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‘
 

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

时间: 2024-07-31 20:50:23

How to execute sudo command in remote host via SSH的相关文章

-bash: sudo: command not found Error and Solution

文章转自: http://www.cyberciti.biz/faq/debian-ubuntu-rhel-centos-linux-bash-sudo-command-not-found/ 安装sudo $ su - and install sudo apt-get install sudo 修改sudo sudo vi /etc/sudoers 安装红色的那一行,添加一个用户 # # This file MUST be edited with the 'visudo' command as

Execute Unix Command via Putty_QTP

plink_path = "C:/plink.exe"     'plink.exe 路径 username = "username"       '用户名 password = "password"       '密码 host = "192.168.0.1"        'Unix/Linux服务器地址 command = "ls"                  '要执行的命令 Set oShel

实战2 Cacti监控Localhost和Remote Host

上篇博文主要讲解了cacti监控host主机,由于上篇博文cacti的版本也不是最新的!所以在实战2更新了cacti的版本,并添加了监控远程服务器和优化轮询 实战2 重点 一.新版cacti监控host 二.新版cacti监控Remote Host 三.新版cacti优化spine轮询 附加 四.网卡流量和存储挂在盘 一.新版cacti监控host 1.安装lamp平台 [[email protected] ~]# yum install -y httpd php php-mysql php-s

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

[email protected]:~$ scp /home/hadoop/.ssh/authorized_keys node3:/home/hadoop/.ssh/ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

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

在配置本机与docker容器实现ssh无密码访问时出现以下报错 # federico @ linux in ~ [18:35:52] C:127$ sudo ssh-copy-id -i .ssh/id_rsa.pub '[email protected]'/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub"/usr/bin/ssh-copy-id: INFO: attemptin

DEPRECATED: Use of this script to execute hdfs command is deprecated.

DEPRECATED: Use of this script to execute hdfs command is deprecated. 本人安装的hadoop版本是2.4.0的,但每次执行命令时都会显示下面的信息 [email protected]_160_34_centos:/usr/local/hadoop-2.4.0> hadoop dfs -ls . DEPRECATED: Use of this script to execute hdfs command is deprecate

scp不可用:WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! After doing ssh are you seeing this error.No problem it can be solved. [email protected]:/tmp# ssh 10.10.0.16 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFI

ssh ip "WARING:REMOTE HOST IDENTIFICATION HAS CHANGED!"

[[email protected] network-scripts]# ssh 192.168.1.10 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOM

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED

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