<p>serverspec is using <a href="https://net-ssh.github.io/ssh/v2/api/classes/Net/SSH/Config.html" rel="nofollow noreferrer">this Ruby class</a> to ssh to servers</p>

<p>One should set the path to the key into the ~/.ssh/config file:</p>

<pre><code>Host X
    HostName X
    User Y
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/Z
</code></pre>

<p>Now <code>rake spec</code> runs the test on the server.</p>

CC BY-SA 3.0
2017-06-15T10:03:40.583Z
2017-06-15T10:03:40.583Z
030
<p><a href="http://serverspec.org/advanced_tips.html" rel="nofollow noreferrer">The serverspec doc</a> indicates that it is possible to login using ssh and serverspec:</p>

<blockquote>
<pre><code>require 'highline/import'

if ENV['ASK_LOGIN_PASSWORD']
  options[:password] = ask("\nEnter login password: ") { |q| q.echo = false }
else
  options[:password] = ENV['LOGIN_PASSWORD']
end

set :ssh_options, options
</code></pre>
</blockquote>

<p>How to login using an ssh key?</p>

<serverspec>
How to login using serverspec using ssh key?
030
# How to login using serverspec using ssh key?

(Asked by: username_0 on 2017-06-15)

The serverspec doc indicates that it is possible to login using ssh and serverspec:

require 'highline/import'

if ENV['ASK_LOGIN_PASSWORD']
  options[:password] = ask("\nEnter login password: ") { |q| q.echo = false }
else
  options[:password] = ENV['LOGIN_PASSWORD']
end

set :ssh_options, options


How to login using an ssh key?

**Tags:** serverspec


---

## 1 answers

### Answer by username_0 on 2017-06-15. Score: 0 | Accepted answer

serverspec is using this Ruby class to ssh to servers
One should set the path to the key into the ~/.ssh/config file:
Host X
    HostName X
    User Y
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/Z

Now rake spec runs the test on the server.


---

