Sources:
- https://medium.com/@lizrice/ssh-to-vagrant-from-vscode-5b2c5996bc0e
- https://www.bloglibre.net/2020/06/28/remotecommand-en-ssh/
# Change to the directory containing the Vagrantfile
~$ cd vagrant/machine
# Get the SSH config that Vagrant uses
~/vagrant/machine$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/liz/vagrant/machine/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
Copy the output SSH config into an file to your ~/.ssh/config
.
Add these lines to the config:
RemoteCommand cd ~/your/directory; bash -l
RequestTTY yes
You will have something that looks like this:
Host vagrant-machine
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/liz/vagrant/machine/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
RemoteCommand cd ~/your/directory; bash -l
RequestTTY yes