Skip to content

Instantly share code, notes, and snippets.

@floptwo
Last active March 6, 2024 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floptwo/89fa88899e3733af13a08326a8130c90 to your computer and use it in GitHub Desktop.
Save floptwo/89fa88899e3733af13a08326a8130c90 to your computer and use it in GitHub Desktop.
How to vagrant ssh into a directory

Sources:

# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment