ssh email@example.com -p 2222 should work fine, but sometimes Vagrant changes the port it’s forwarding to the localhost so the
-p 2222 won’t work.
So double-check what port SSH is being forwarded on/from and use that port number instead.
A simple way to check that is to
vagrant ssh from your Vagrant setup directory and then in another shell/terminal window run this command:
ps aux | grep ssh
There should be a line in there that shows you exactly how the SSH connection was established that looks like this:
ssh firstname.lastname@example.org -p 2226 -o Compression=yes -o DSAAuthentication=yes -o LogLevel=FATAL -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /path/to/Vagrant/.vagrant/machines/nodejs/virtualbox/private_key
Ignore the bulk of that command unless you care about password-less access. Just note this first part:
ssh email@example.com -p 2226
That is the command—in my example—where the forwarded SSH post is
2226. That works in my case. And if you are prompted for a password for some reason, remember the default Vagrant user is
vagrant and the default password for that user is…