[英]can't access ec2 instance which is created by ruby aws-sdk lib using ssh?
[英]Using SCP/SSH in Ruby with a pem file in an Amazon EC2 instance
嘗試使用Ruby腳本從Amazon EC2(Ubuntu)實例遠程傳輸或運行命令。 我無法從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)
我也試過使用命令行,但這里的問題是主機是動態的,我必須每次都驗證'是'
`/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
除了不使用命令行代碼禁用SSH主機密鑰檢查之外,還有其他方法嗎? 或者,對於ruby,net-scp或net-ssh gem中是否有選項?
Ruby解決方案,我在他們的任何文檔中都找不到
Net::SSH.start( hostname, username, :keys => "/path/to/keyfile.pem" ) do|ssh|
#process
end
嘗試這樣的命令
ssh -o StrictHostKeyChecking=no -i keyfile.pem -r username@some.random.ip
您還可以將以下行添加到〜/ .ssh / config文件中,以避免使用-o命令行開關
Host *
StrictHostKeyChecking no
注意:您應該將*替換為您訪問的遠程服務器的域名模式
同樣也適用於scp
要添加到naveed聲明的內容,如果要為Net::SCP.upload!
指定PEM文件Net::SCP.upload!
例如,使用命令: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
我從naveed的例子和查看文檔中找到了它 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.