title: Using SCP/SSH in Ruby with a pem file in an Amazon EC2 instance
body: <p>Trying to transfer or run commands remotely from an Amazon EC2(Ubuntu) instance with a Ruby script.
  I am not able to figure out from the ruby doc for ssh and scp how the .pem file can be passed for authentication</p>
  
  <pre><code># download a file from a remote server
  Net::SCP.download!("remote.host.com", "username",
  "/remote/path", "/local/path",
  :password =&gt; password)
  </code></pre>
  
  <p>I have also tried using command line but the issue here is the host is dynamic and I would have to authenticate 'yes' everytime</p>
  
  <pre><code>`/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
  </code></pre>
  
  <p>Is there any way other than by not disabling SSH host key checking with the command line code. Or is there an option in the net-scp or the net-ssh gem for ruby?</p>