Ylianst/MeshCentralRouter

Enhancements for including in scripts (e.g. SSH ProxyCommand)

ShaunMaher opened this issue · 0 comments

I have just started using MeshCentralRouter on Linux as a way of connecting to remote devices with SSH. I do similar things with SSH over cloudflared (formerly argo) tunnels and SSH over SSH.

I was somewhat surprised to find that this is quite simple to do with MeshCentralRouter as well. This is going to make my day job much more efficient. There are just a few small tweaks needed before it's "perfect".

This is what I am using as "ProxyCommand" in my SSH config file:

Host <target hostname>
  user    <username>
  ProxyCommand  bash -c 'PORT=$(freeport); nohup wine Z:\\home\\<username>\\Downloads\\MeshCentralRouter.exe -map:TCP:${PORT}:<name in meshcentral>::22 -tray & loop=1; while [ $loop -gt 0 ]; do socat tcp:127.0.0.1:${PORT} STDIO 2>/dev/tty; loop=$?; sleep 0.5; done' 2>/dev/tty

freeport is another external script that picks a random local listening port number and makes sure it's not in use.

This method is not without quirks though.

I can't see a nice way to detect when MeshCentralRouter.exe has established the connection. I'm running a loop that tries to connect repeatedly until it connects. This will become an infinite loop if the connection never becomes available (e.g. cancelling the MeshCentralRouter.exe login dialogue). It would be awesome if MeshCentralRouter.exe wrote to stdout or to a log some message that indicates that the connection was established. I tried adding the "-debug" command line argument but I couldn't find where the log was written to.

This method starts a new instance of MeshCentralRouter.exe each time I use it. If I'm connecting to multiple servers, I get multiple instances of MeshCentralRouter.exe running and therefore multiple tray icons. It would be great if there was a way to tell an existing running instance of MeshCentralRouter.exe to add another mapping. That would also mean I don't need to re-authenticate with MeshCentral for each connection, just the first. I guess this means having a way to communicate with the running MeshCentralRouter.exe instance (other than by the UI) and having it add a mapping.

Any guidance anyone can offer to help streamline my process?