Package: local-ssh-config
local-ssh-configIan Cleary (iancleary)DescriptionWelcome!This is a CLI to generate/update SSH config files for your local virtual machines quickly.ProblemWindows doesn't maintain a static IP Address of Hyper-V Virtual Machines across reboots.  When usingmultipasswith a Hyper-V backend, this applies as well for multipass.This leads to ssh configuration, which is by ip address, to be stale every reboot.SolutionThis script updates my ssh config file for meget IP address from PowerShell for hyper-v by name according to source ('hyper-v' directly, or 'multipass list')write template config files to the~/.ssh/config.d/directory according to your~/.config/local-ssh-config/settings.jsonfile.This assumes you have:a~/.ssh/config.d/folderInclude config.d/*in your~/.ssh/configFor Hyper-V Virtual MachinesPowerShell installedHyper-V enabled and The Hyper-V Manager InstalledHyper-V Manager IP AddressI currently use Ubuntu Servers, if you do too,please install severalaptpackages in the Virtual Machine (so that Hyper-V can report the IP Address)🚨🚨 Hyper-V will not report the ip address until you do the above 🚨🚨Multipass or Virtual Box may report the IP address of an Ubuntu Guest. I'm not currently sure if it's a Hyper-V limitation or a Windows limitation.As this tool only currently supports Hyper-V, please consider this a warning of the required step.Quickstart❯pipxinstalllocal-ssh-config--user
❯local-ssh-config--helpThat will output the following:Usage:local_ssh_config[OPTIONS]Createsan`~/.ssh/config.d/`directory,checkstoseeifyouincludeallfilesinthatdirectory,andthencreatesconfigfilesforeachvirtualmachinespecifiedinyour`~/.config/vm-ip-ssh-config/settings.json`file.Seehttps://github.com/iancleary/local-ssh-config/formoreinformation.

Arguments:None

Options:-f,--fileTEXTTheJSONfilecontainingthevirtualmachineconfiguration[default:C:\Users\username\.config\vm-ip-ssh-config\settings.json]-v,--versionShowtheapplication'sversionandexit.--install-completionInstallcompletionforthecurrentshell.--show-completionShowcompletionforthecurrentshell,tocopyitorcustomizetheinstallation.--helpShowthismessageandexit.Example UsageThe first and only argument is the name of the component to create.$local-ssh-config{'host':'test.local','hostname':'0.0.0.0','user':'test','identity_file':'~/.ssh/example_id_ed25519'}{'host':'ubuntu.local','hostname':{'source':'hyper-v','physical_address':'00-15-5d-95-fb-09'},'user':'icleary','identity_file':'~/.ssh/github_id_rsa_ed25519'}Hyper-V:Powershell(arp-a):Interfacecommandexecutedsuccessfully!
-------------------------{'host':'dev1.multipass.local','hostname':{'source':'multipass','name':'dev1'},'user':'ubuntu'}Multipass-V:Powershell(multipasslist):Interfacecommandexecutedsuccessfully!
-------------------------

✨Creating~/.ssh/config.d/files
✅C:\Users\icleary\.ssh\config.d\test.local
✅C:\Users\icleary\.ssh\config.d\ubuntu.local
✅C:\Users\icleary\.ssh\config.d\dev1.multipass.local
SSHconfigupdated!🚀✨!

Thankyouforusinglocal-ssh-config.The path printed is the absolute path to the updated config files.This uses a directory~/.ssh/config.d/to allow for a single file per Host, to allow cleaner version tracking within a dotfile manager.
SeeInclude config.d/*in your~/.ssh/configfor the include syntaxWINDOWS_MULTIPASS_DEFAULT_ID_RSA= "C:/Windows/System32/config/systemprofile/AppData/Roaming/multipassd/ssh-keys/id_rsa"ConfigurationConfiguration can be done through 2 different ways:Creating a globalsettings.jsonin your home directory (~/.config/local-ssh-config/settings.json).Creating a local.local-ssh-config-config.jsonin your project's root directory and including the path to that file with the--for-foptionanl command-line argument.The optional command line value takes precendence global settings file being the default.API ReferenceFileControls the settings.json to load.
Defaults to~/.config/local-ssh-config/settings.jsonUsage:Command line:--file <value>or-f <value>JSON config:Example with single host, as dictionary{"host":"ubuntu.local","hostname":{"source":"hyper-v","physical_address":"00-15-5d-95-fb-09"},"user":"icleary","identity_file":"~/.ssh/github_id_rsa_ed25519"}Example with single host, as list:[{"host":"ubuntu.local","hostname":{"source":"hyper-v","physical_address":"00-15-5d-95-fb-09"},"user":"icleary","identity_file":"~/.ssh/github_id_rsa_ed25519"}]A single dictionary is converted to a list of hosts before looping through the files, so either structure is valid (your preference).Example with multiple hosts:[{"host":"test.local","hostname":"0.0.0.0","user":"test","identity_file":"~/.ssh/example_id_ed25519"},{"host":"ubuntu.local","hostname":{"source":"hyper-v","physical_address":"00-15-5d-95-fb-09"},"user":"icleary","identity_file":"~/.ssh/github_id_rsa_ed25519"},{"host":"dev1.multipass.local","hostname":{"source":"multipass","name":"dev1"},"user":"ubuntu"}]Further informationI will likely evolve this CLI as I learn more; I'm on my way 😊Enjoy quickly updating your ssh configurations 🚀!ContributingI created this CLI for my opinionated uses and may not accept changes.  That said, I made this to solve a problem, and if you have the same problem, I hope it helps you! 😊SeeCONTRIBUTING.md.