【发布时间】:2012-12-01 09:54:11
【问题描述】:
我的环境为用户配置了 SSH 无密码身份验证 节点服务器(Rundeck 服务器)和节点目标(远程 Solaris 主机)之间的“主”。
在 Target 上,我想用用户 appmanager 执行脚本 /app/acme/stopApp.sh。
通常,当我需要手动运行脚本时,我会使用:
ssh master@server sudo su - appmanager
或者简单地说:
ssh -t master@server 'sudo su - appmanager'
无需密码即可运行并最终运行(作为 appmanager):
/app/acme/stopApp.sh
但我无法弄清楚如何使用 Net::SSH 重现这些步骤。
当我执行sudo su - appmanager 然后/app/acme/stopApp.sh,
我是在子shell中做的,对吧?
require 'rubygems'
require 'net/ssh'
require 'net/scp'
require 'crypt/blowfish'
require 'yaml'
#
# ...
#
Net::SSH.start( host, user, :password => password ) do |session|
# It's possible to proceed in this way?
cmd = 'sudo su - appmanager;/app/acme/stopApp.sh'
ses = session.exec!( cmd )
end
我意识到,如果我尝试在目标服务器上执行类似的操作:
sudo su -c /app/acme/stopApp.sh appmanager
我收到以下消息:
We trust you have received the usual lecture from the local System Administrator.
It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility. Password:
Password:
【问题讨论】:
-
感谢铁皮人对文本的改进。我不是以英语为母语的人,所以你的行为可以帮助我更多地了解这种语言。
标签: shell ssh remote-access net-ssh rundeck