Last active
March 31, 2024 17:07
-
-
Save shadyvb/cd06ee086ab0f1f8e0898717a2f036f3 to your computer and use it in GitHub Desktop.
Revisions
-
shadyvb revised this gist
Jun 3, 2019 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,3 +23,6 @@ curl https://gist.github.com/shadyvb/cd06ee086ab0f1f8e0898717a2f036f3 - Do a `vagrant up` on any of your vagrant machines - Assuming your vagrant machine host name is: `client.local` - Try to `ssh cient.local` # Next up: - 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 the `ProxyCommand` directive which can be scripted. But performance isn't the same as using the direct `ssh HOSTNAME.LOCAL` trick enclosed. Still an interesting idea nonetheless. -
shadyvb revised this gist
Jun 3, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ This will let you SSH into any vagrant machine quickly, using its host name, and 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.github.com/shadyvb/cd06ee086ab0f1f8e0898717a2f036f3/raw/834fb36fe1fd99afeacf189886e89ee3d0e62640/VagrantFile > ~/.vagrant.d/VagrantFile -
shadyvb revised this gist
Jun 3, 2019 . 1 changed file with 1 addition and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,13 +11,7 @@ mkdir ~/.ssh/config.d &>/dev/null 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.github.com/shadyvb/cd06ee086ab0f1f8e0898717a2f036f3/raw/834fb36fe1fd99afeacf189886e89ee3d0e62640/VagrantFile > ~/.vagrant.d/VagrantFile ``` # Explanation: -
shadyvb revised this gist
Jun 3, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,8 +10,8 @@ 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 cat << EOF > ~/.vagrant.d/VagrantFile Vagrant.configure("2") do |config| config.trigger.after :up, name: "Caching vagrant ssh-config for '#{CONF['hosts'].join('\' and \'')}'", -
shadyvb revised this gist
Jun 3, 2019 . 2 changed files with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,5 +2,4 @@ Vagrant.configure("2") do |config| config.trigger.after :up, name: "Caching vagrant ssh-config for '#{CONF['hosts'].join('\' and \'')}'", ruby: proc{|env,machine| puts `mkdir ~/.ssh/config.d &>/dev/null; vagrant ssh-config | sed 's/Host default/Host #{CONF['hosts'].join(" ")}/' | tee ~/.ssh/config.d/vagrant-#{CONF['hosts'][0]} >/dev/null; bash -c "if ! grep -q 'Include ~/.ssh/config.d/*' ~/.ssh/config; then echo '> Please add the following line to your ~/.ssh/config file: Include ~/.ssh/config.d/*'; fi"`} end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,6 @@ Vagrant.configure("2") do |config| config.trigger.after :up, name: "Caching vagrant ssh-config for '#{CONF['hosts'].join('\' and \'')}'", ruby: proc{|env,machine| puts `mkdir ~/.ssh/config.d &>/dev/null; vagrant ssh-config | sed 's/Host default/Host #{CONF['hosts'].join(" ")}/' | tee ~/.ssh/config.d/vagrant-#{CONF['hosts'][0]} >/dev/null; bash -c "if ! grep -q 'Include ~/.ssh/config.d/*' ~/.ssh/config; then echo '> Please add the following line to your ~/.ssh/config file: Include ~/.ssh/config.d/*'; fi"`} end EOF ``` -
shadyvb revised this gist
Jun 3, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # TL;DR; This will let you SSH into any vagrant machine quickly, using its host name, and without further manual steps. ### Quick setup: ``` -
shadyvb revised this gist
Jun 3, 2019 . 2 changed files with 34 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,6 @@ Vagrant.configure("2") do |config| config.trigger.after :up, name: "Caching vagrant ssh-config for '#{CONF['hosts'].join('\' and \'')}'", ruby: proc{|env,machine| puts `mkdir ~/.ssh/config.d &>/dev/null; vagrant ssh-config | sed 's/Host default/Host #{CONF['hosts'].join(" ")}/' | tee ~/.ssh/config.d/vagrant-#{CONF['hosts'][0]} >/dev/null; bash -c "if ! grep -q 'Include ~/.ssh/config.d/*' ~/.ssh/config; then echo '> Please add the following line to your ~/.ssh/config file: Include ~/.ssh/config.d/*'; fi"`} end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ # TL;DR; This will let you SSH into any vagrant machine quickly, using your host name, and without further manual steps. ### Quick setup: ``` # 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 cat << EOF > ~/.vagrant/VagrantFile Vagrant.configure("2") do |config| config.trigger.after :up, name: "Caching vagrant ssh-config for '#{CONF['hosts'].join('\' and \'')}'", ruby: proc{|env,machine| puts `mkdir ~/.ssh/config.d &>/dev/null; vagrant ssh-config | sed 's/Host default/Host #{CONF['hosts'].join(" ")}/' | tee ~/.ssh/config.d/vagrant-#{CONF['hosts'][0]} >/dev/null; bash -c "if ! grep -q 'Include ~/.ssh/config.d/*' ~/.ssh/config; then echo '> Please add the following line to your ~/.ssh/config file: Include ~/.ssh/config.d/*'; fi"`} end EOF ``` # Explanation: - 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 new `ssh_config` entry under `~/.ssh/config.d` each time you do a `vagrant up`, so you can just `ssh HOSTNAME.LOCAL` any time and get a milliseconds execution time, instead of the many seconds you get with `vagrant 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` # Try it! - Do a `vagrant up` on any of your vagrant machines - Assuming your vagrant machine host name is: `client.local` - Try to `ssh cient.local` -
shadyvb created this gist
Jun 3, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ # Apparently.. you can have a global VagrantFile! # .. that gets executed for all vagrant machines, and can be found/created # .. at `~/.vagrant.d/VagrantFile`. # .. Create/update the file to include the uncommented code below. # # Explanation: As a workaround to slow `vagrant ssh` calls, # .. this piece of code will auto-create a new `ssh_config` entry under `~/.ssh/config.d` # .. each time you do a `vagrant up`, so you can just `ssh HOSTNAME.LOCAL` any time and get # .. a milliseconds execution time, instead of the many seconds you get with `vagrant ssh` # # Pre-requiste: You need to have this line in your `~/.ssh/config` to allow loading of # .. custom ssh_config files in `~/.ssh/config.d`: # `Include ~/.ssh/config.d` Vagrant.configure("2") do |config| config.trigger.after :up, name: "Caching vagrant ssh-config for '#{CONF['hosts'].join('\' and \'')}'", ruby: proc{|env,machine| puts `mkdir ~/.ssh/config.d &>/dev/null; vagrant ssh-config | sed 's/Host default/Host #{CONF['hosts'].join(" ")}/' | tee ~/.ssh/config.d/vagrant-#{CONF['hosts'][0]} >/dev/null; bash -c "if ! grep -q 'Include ~/.ssh/config.d/*' ~/.ssh/config; then echo '> Please add the following line to your ~/.ssh/config file: Include ~/.ssh/config.d/*'; fi"`} end