sshssh-keysopensshinspec

inspect ssh connection is not working but ssh connection is allow


I am trying to run all my inspec test before to deploy the chef recipe. I want to know what is the initial state of my instances.

I tested the ssh connection with:

ssh -i $HOME/key.pem centos@server_ip_address

and the connection is allow, but when I tried to run the inspect test again the server:

inspec exec ntp/test/integration/ntp.rb -t ssh://centos@server_ip_address -i /home/centos/key.pem

I got this error:

I, [2017-01-17T14:10:32.835995 #2416]  INFO -- : [SSH] connection failed, retrying in 1 seconds (#<Net::SSH::AuthenticationFailed: Authentication failed for user centos@server_ip_address>)
I, [2017-01-17T14:10:34.619150 #2416]  INFO -- : [SSH] connection failed, retrying in 1 seconds (#<Net::SSH::AuthenticationFailed: Authentication failed for user centos@server_ip_address>)
I, [2017-01-17T14:10:36.403860 #2416]  INFO -- : [SSH] connection failed, retrying in 1 seconds (#<Net::SSH::AuthenticationFailed: Authentication failed for user centos@server_ip_address>)
I, [2017-01-17T14:10:38.188401 #2416]  INFO -- : [SSH] connection failed, retrying in 1 seconds (#<Net::SSH::AuthenticationFailed: Authentication failed for user centos@server_ip_address>)
W, [2017-01-17T14:10:39.971832 #2416]  WARN -- : [SSH] connection failed, terminating (#<Net::SSH::AuthenticationFailed: Authentication failed for user centos@server_ip_address>)
Transport error, can't connect to 'ssh' backend: SSH session could not be established

I do not know where is the error. Any suggestion ?

Inspec info

chef gem list | grep inspec

inspec (1.9.0, 1.7.2)

Solution

  • Well, I spent the whole morning and part of the afternoon searching and I found a solution here

    I execute:

    eval "$(ssh-agent)"
    

    and then added my key to the agent:

    ssh-add key.pem
    

    So now I am able to run the inspec tests without the keys just executing:

    inspec exec cookbooks/ntp/test/integration/default/ -t ssh://centos@server_ip_address
    

    Ok, this is a partial solution because I am still looking for using the -i and use the key as argument. The issue is still there.