Connecting To a Test Kitchen Instance Via SFTP, SSH, or SCP

If you are using Chef and Test Kitchen to test your cookbooks you may have need to connect to the Test Kitchen VM in some other fashion other than $ kitchen login instance-name.

To do so:

Do a $ kitchen list to see the running vms

kitchen list
Instance                      Driver   Provisioner  Verifier  Transport  Last Action
default-centos-66             Vagrant  ChefSolo     Busser    Ssh        Converged

Then look in the .kitchen directory from where you ran your $ kitchen command and look for the corresponding .yml config file for the vm

ls .kitchen
default-centos-66.yml  kitchen-vagrant  logs

Inside the .yml file for the vm is the path to the ssh key

more .kitchen/default-centos-66.yml
---
hostname: 127.0.0.1
port: '2222'
username: vagrant
ssh_key: "/home/rchapin/.vagrant.d/insecure_private_key"
last_action: converge

With that, just use the -i argument to point to the identity file and sftp to the box

sftp -P 2222 -i /home/rchapin/.vagrant.d/insecure_private_key vagrant@127.0.0.1

If the VM prompts you for a user name when logging in, you can always login via kitchen, change the password for that user and then retry

To login via kitchen issue the following command:

kitchen login default-centos-66

Leave a Reply