Running vagrant ssh
can be slow because it boots up a ruby process, does a bunch of analysis to determine your ssh parameters, and then actually invokes the command. If you want a faster login, try the following:
# Compute the ssh parameters, append them to your global ssh config file
# The --host parameter specifies what you want the vagrant machine to be called
vagrant ssh-config --host vagrant >> ~/.ssh/config
# Now just ssh into that machine directly
ssh vagrant
A couple caveats:
- Vagrant still needs to be running for you to ssh into it.
vagrant ssh
fails with a helpful error message when the machine isn't running, whilessh vagrant
will just fail silently. Not super helpful. - If you do a bunch of fiddling with vagrant, it's possible that the parameters in your .ssh/config file may become out of date. I've been running this configuration for several months now without any problems but ymmv. To fix that issue, open your .ssh/config file, delete the block that starts with "Host vagrant" and then run the first command again.
Here's a little script I wrote, it also checks that the config is valid (by testing the ssh connection) and regenerates it if not:
https://gist.github.com/chriscz/ee552707efc142844c049b1778e99957
Tested on Fedora 36.