Stop SSH password prompts in serverspec

时间:2015-06-15 14:55:27

标签: ruby net-ssh serverspec

I'm in an environment with authentication tokens, so typically a SSH password is not required. My serverspec tests are always asking me for a password. Is there a way to prevent this?

No password required:

$ ssh atlspf01
newatson@atlspf01:~$

Yet, in serverspec

$ rake spec
Password:

Relevant code in spec_helper.rb

require 'serverspec'
require 'net/ssh'

set :backend, :ssh
...
set :host, ENV['TARGET_HOST']
set :ssh_options, :user => ENV['USERNAME']

UPDATE: Problem is that net::ssh does not support Kerberos authentication (gssapi-with-mic). Use ssh::ssh::kerberos or use ssh keys.

1 个答案:

答案 0 :(得分:1)

在您的配置中,您只会将有关用户的信息传递给ssh_options

假设您的目标主机存储在环境变量TARGET_HOST中并且用户名存储在USERNAME中,您应该执行以下操作:

set :ssh_options, Net::SSH::Config.for(ENV['TARGET_HOST']).merge(user: ENV['USERNAME'])