» SSH Sharing

Vagrant share makes it trivially easy to allow remote SSH access to yourVagrant environment by supplying the —ssh flag to vagrant share.

Easy SSH sharing is incredibly useful if you want to give access toa colleague for troubleshooting ops issues. Additionally, it enablespair programming with a Vagrant environment, if you want!

SSH sharing is disabled by default as a security measure. To enableSSH sharing, simply supply the —ssh flag when calling vagrant share.

» Usage

Just run vagrant share —ssh!

When SSH sharing is enabled, Vagrant generates a brand new keypair forSSH access. The public key portion is automatically insertedinto the Vagrant machine, and the private key portion is provided to theuser connecting to the Vagrant share. This private key is encrypted usinga password that you will be prompted for. This password is never transmittedacross the network by Vagrant, and is an extra layer of security preventinganyone who may know your share name from easily accessing your machine.

After running vagrant share —ssh, it will output the name of your share:

  1. $ vagrant share --ssh
  2. ==> default: Detecting network information for machine...
  3. default: Local machine address: 192.168.84.130
  4. ==> default: Generating new SSH key...
  5. default: Please enter a password to encrypt the key:
  6. default: Repeat the password to confirm:
  7. default: Inserting generated SSH key into machine...
  8. default: Local HTTP port: disabled
  9. default: Local HTTPS port: disabled
  10. default: SSH Port: 2200
  11. ==> default: Creating Vagrant Share session...
  12. share: Cloning VMware VM: 'hashicorp/vagrant-share'. This can take some time...
  13. share: Verifying vmnet devices are healthy...
  14. share: Preparing network adapters...
  15. share: Starting the VMware VM...
  16. share: Waiting for machine to boot. This may take a few minutes...
  17. share: SSH address: 192.168.84.134:22
  18. share: SSH username: tc
  19. share: SSH auth method: password
  20. share:
  21. share: Inserting generated public key within guest...
  22. share: Removing insecure key from the guest if it's present...
  23. share: Key inserted! Disconnecting and reconnecting using new SSH key...
  24. share: Machine booted and ready!
  25. share: Forwarding ports...
  26. share: -- 31338 => 65534
  27. share: -- 22 => 2202
  28. share: SSH address: 192.168.84.134:22
  29. share: SSH username: tc
  30. share: SSH auth method: password
  31. share: Configuring network adapters within the VM...
  32. ==> share:
  33. ==> share: Your Vagrant Share is running! Name: bazaar_wolf:sultan_oasis
  34. ==> share:
  35. ==> share: You're sharing with SSH access. This means that another can SSH to
  36. ==> share: your Vagrant machine by running:
  37. ==> share:
  38. ==> share: vagrant connect --ssh bazaar_wolf:sultan_oasis
  39. ==> share:

Anyone can then SSH directly to your Vagrant environment by runningvagrant connect —ssh NAME where NAME is the name of the share outputtedpreviously.

  1. $ vagrant connect --ssh bazaar_wolf:sultan_oasis
  2. Loading share 'bazaar_wolf:sultan_oasis'...
  3. The SSH key to connect to this share is encrypted. You will
  4. require the password entered when creating the share to
  5. decrypt it. Verify you have access to this password before
  6. continuing.
  7. Press enter to continue, or Ctrl-C to exit now.
  8. Password for the private key:
  9. Executing SSH...
  10. Welcome to Ubuntu 12.04.3 LTS (GNU/Linux 3.8.0-29-generic x86_64)
  11. * Documentation: https://help.ubuntu.com/
  12. Last login: Fri Mar 7 17:44:50 2014 from 192.168.163.1
  13. vagrant@vagrant:~$

If the private key is encrypted (the default behavior), then the connectingperson will be prompted for the password to decrypt the private key.