[英]Using SCP/SSH in Ruby with a pem file in an Amazon EC2 instance
Trying to transfer or run commands remotely from an Amazon EC2(Ubuntu) instance with a Ruby script. 尝试使用Ruby脚本从Amazon EC2(Ubuntu)实例远程传输或运行命令。 I am not able to figure out from the ruby doc for ssh and scp how the .pem file can be passed for authentication
我无法从ruby doc中了解ssh和scp如何传递.pem文件进行身份验证
# download a file from a remote server
Net::SCP.download!("remote.host.com", "username",
"/remote/path", "/local/path",
:password => password)
I have also tried using command line but the issue here is the host is dynamic and I would have to authenticate 'yes' everytime 我也试过使用命令行,但这里的问题是主机是动态的,我必须每次都验证'是'
`/usr/bin/scp -i keyfile.pem -r username@some.random.ip:/remote/path /local/path`
The authenticity of host 'some.random.ip (some.random.ip)' can't be established.
ECDSA key fingerprint is some:random:fingerprint.
Are you sure you want to continue connecting (yes/no)? yes
Is there any way other than by not disabling SSH host key checking with the command line code. 除了不使用命令行代码禁用SSH主机密钥检查之外,还有其他方法吗? Or is there an option in the net-scp or the net-ssh gem for ruby?
或者,对于ruby,net-scp或net-ssh gem中是否有选项?
Ruby solution which I did not find in any of their docs Ruby解决方案,我在他们的任何文档中都找不到
Net::SSH.start( hostname, username, :keys => "/path/to/keyfile.pem" ) do|ssh|
#process
end
try a command like this 尝试这样的命令
ssh -o StrictHostKeyChecking=no -i keyfile.pem -r username@some.random.ip
You can also add the following line to your ~/.ssh/config file, to avoid using -o commandline switch 您还可以将以下行添加到〜/ .ssh / config文件中,以避免使用-o命令行开关
Host *
StrictHostKeyChecking no
Note: you should probably replace * with the domain name pattern of the remote servers you access 注意:您应该将*替换为您访问的远程服务器的域名模式
The same should also work with scp
同样也适用于
scp
To add to what naveed stated, if you want to specify a PEM file for Net::SCP.upload!
要添加到naveed声明的内容,如果要为
Net::SCP.upload!
指定PEM文件Net::SCP.upload!
command for example use the :ssh
hash key to specify the :keys
hash key value: 例如,使用命令
:ssh
hash key指定:keys
哈希键值:
Net::SCP.upload!("remote.host.com", "username",
"/local/path", "/remote/path", :ssh => { :keys => "/path/to/keyfile.pem" }) do |ch, name, sent, total|
...
end
I figured it out from naveed's example and from looking at the documentation . 我从naveed的例子和查看文档中找到了它 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.