This will let you SSH into any vagrant machine quickly, using its host name, and without further manual steps.
# Create the ~/.ssh/config.d folder
mkdir ~/.ssh/config.d &>/dev/null
# Make sure it is included in your ~/.ssh/config
bash -c "if ! grep -q 'Include ~/.ssh/config.d/*' ~/.ssh/config; then cp ~/.ssh/config ~/.ssh/config.backup; { echo 'Include ~/.ssh/config.d/*'; cat ~/.ssh/config; } | tee ~/.ssh/config >/dev/null; fi"
# Copy the global VagrantFile to your ~/.vagrant.d
curl https://gist.githubusercontent.com/shadyvb/cd06ee086ab0f1f8e0898717a2f036f3/raw/834fb36fe1fd99afeacf189886e89ee3d0e62640/VagrantFile > ~/.vagrant.d/VagrantFile
- Apparently.. you can have a global VagrantFile! And that gets executed for all vagrant machines, and can be found/created at
~/.vagrant.d/VagrantFile
. - As a workaround to slow
vagrant ssh
calls, this piece of code will auto-create a newssh_config
entry under~/.ssh/config.d
each time you do avagrant up
, so you can justssh HOSTNAME.LOCAL
any time and get a milliseconds execution time, instead of the many seconds you get withvagrant ssh
- In order for your SSH config to pick up the new config files, you need to include the new folder in your
~/.ssh/config
file by adding the following to the beginning of the file:Include ~/.ssh/config.d
- Do a
vagrant up
on any of your vagrant machines - Assuming your vagrant machine host name is:
client.local
- Try to
ssh cient.local
- I've been expirementing with a magical dynamic
ssh vagrant
command that detects SSH connection information from the vagrant machine in the current folder, for which I've been playing with theProxyCommand
directive which can be scripted. But performance isn't the same as using the directssh HOSTNAME.LOCAL
trick enclosed. Still an interesting idea nonetheless.
if you're looking for a ruby idiomatic option to accomplish the same, here it is: