- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我一直在尝试使用 Thor 编写一个小型库,以帮助我快速创建新项目和站点。我写了这个小方法:
def ssh(cmd)
Net::SSH.start( server_ip, user, :port => port) do |session|
session.exec cmd
end
end
只是协助我在需要时在远程服务器上运行快速命令。
问题是当我需要在远程端的 sudo 下运行命令时,脚本似乎卡在我身上。例如当执行这个...
ssh("sudo cp #{file_from_path} #{file_to_path}" )
脚本会提示我输入密码
[sudo] password for user:
但是在输入之后整个事情就挂起。
有人会碰巧知道它为什么挂起吗,以及我可以做什么来在 Net::SSH(或其他替代方案)下的远程服务器上运行 sudo 命令?
*注意:在提出建议之前,我最初是在 Capistrano 下将这个库作为食谱编写的,直到我遇到了 Thor,并认为这是一个尝试它的好机会。我不反对在需要时将整个事情切换回 Capistrano,但如果没有一种在远程服务器上运行 sudo 命令的简单方法,我会感到非常惊讶。
最佳答案
我希望这对搜索的人有所帮助。我还需要在部署期间 sudo
(重新启动瘦实例)
# deploy.rake
require 'net/ssh'
# INITIALIZE CONSTANTS HERE
HOST = 'yourwebsite.com'
USER = 'admin'
PASSWORD = 'your server password' # or use ENV variables?
# etc.
namespace :deploy do
namespace :staging do
task :restart do
commands = [
"cd #{PATH_TO_STAGING_APP} && git checkout master",
"git reset --hard HEAD",
"git pull origin master",
"bundle install --without test development",
"sudo thin restart -C /etc/thin/#{STAGING_APP}.yml"
]
Net::SSH.start(HOST, USER, :password => PASSWORD) do |ssh|
ssh.open_channel do |channel|
channel.request_pty do |ch, success|
if success
puts "Successfully obtained pty"
else
puts "Could not obtain pty"
end
end
channel.exec(commands.join(';')) do |ch, success|
abort "Could not execute commands!" unless success
channel.on_data do |ch, data|
puts "#{data}"
channel.send_data "#{PASSWORD}\n" if data =~ /password/
end
channel.on_extended_data do |ch, type, data|
puts "stderr: #{data}"
end
channel.on_close do |ch|
puts "Channel is closing!"
end
end
end
ssh.loop
end
end
end
end
注意一个 channel 只能执行一个命令。因此,我将命令与 commands.join(';')
关于ruby - Net::SSH sudo 命令在输入密码后挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3356878/
sudo 命令 1、sudo 简介 sudo是linux系统管理指令,是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具,如halt,reboot,su等等。这样不仅减少了root用户
我正在尝试更改 source.list。 主机有一个用户 deploy 和密码 deploy 我可以连接 ssh 并使用 sudo 对 source.list 进行任何操作。然而 ansible 似乎
我希望以我当前用户的权限运行 TOMCAT,而不是 root 的环境变量。 vagrant@dev:~/Workspace/eurekastreams$ echo $JAVA_OPTS -Xmx102
这个问题在这里已经有了答案: How to install python modules without root access? (9 个回答) 3年前关闭。 最终目标是在 redhat 机器上的
我一直在尝试允许 EC2 亚马逊服务器('ec2-user')的普通用户访问某个库。 我做了:“sudo chown -R ec2-user/usr”,我现在意识到这是一个致命的错误。它起作用了,但是
我正在尝试使用 cgi (python) 配置 apache2。为此,我必须更改某些文件夹和文件的权限,但每次尝试更改文件或文件夹的权限时,我都会收到 sudo fatal error 。 例如: 1
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我不想在 sudoers 文件中禁用 requiretty。请建议当我在 cron 作业中执行脚本时是否有其他方式启动终端 最佳答案 这可能是一个奇怪的解决方法,但您可以使用 -t 选项通过 cron
寻找将当前用户的别名传递给 sudo 的方法命令,我找到了以下 on ArchWiki : Passing aliases If you use a lot of aliases, you might
我已将 Royal TS 设置为在多台 Linux 计算机上使用我的用户名自动登录。我想让它在连接后自动运行 sudo su -,输入我的密码,这样只需双击连接即可获得 root 权限。 我已经通过创
我正在尝试使用涉及使用 sudo 的子进程。 它在终端中运行良好: sudo /home/pi/Desktop/fm_transmitter/bin/Release/fm_transmitter
我想通过 ssh 连接到远程服务器,更改用户然后执行脚本。我正在使用 subprocess 来执行此操作,但似乎 sudo -u userB -i 并未更改用户。 HOST = 'remote_ser
我正在尝试使用 Ansible 来配置一个 Vagrant 框和一个 EC2 服务器。使用 --connection=local 时,它在 Vagrant 框上工作正常,但似乎只是忽略了 sudo:
嗨,我为 Ansible 编写了一个剧本来安装一些应用程序。我遇到了麻烦,因为我必须以 root 身份运行所有东西,这不是一个好主意。 所以我创建了一个 sudo 用户并创建了一个用于身份验证的私钥。
我想通过 electron 写一个应用程序,但要求是更新需要 root 的文件允许。 通过 cli 很容易实现,就像 sudo vi xxx . 是否可以通过 electron 更新文件? ? 最佳答
我已经安装了以下 pkgs: ii tigervnc-common 1.10.1+dfsg-1 amd
我有一个经销商 Web 服务器,正在将其迁移到新计算机中。源服务器所有者提供了一个用户(我们称之为用户 A),该用户对其他用户具有 sudo 访问权限,但对 root 没有权限。我的用户没有对我需要提
use std::fs::OpenOptions; use std::io::Write; fn main() { let mut source_list = OpenOptions::new
我正在尝试使用命令 sudo jupyterhub 启动 JupyterHub。这会启动服务器,但用户无法登录。但是,当我使用 sudo -s 切换到 root 用户,然后输入 jupyterhub
我正在尝试安装 pip,但我在 StackOverflow 中陷入了相互冲突的答案中(请阅读末尾的评论以了解重复的问题)。 instructions说下载get-pip.py并使用 phyton 运行
我是一名优秀的程序员,十分优秀!