Introducing vSSH - Go Library to Execute Commands Over SSH at Scale
<p><a href="https://www.linkedin.com/in/mehrdadrad/">Mehrdad Arshad Rad</a>, Sr. Principal Software Engineer, Verizon Media</p><p><a href="https://github.com/yahoo/vssh">vSSH</a> is a high performance Go library designed to execute shell commands remotely on tens of thousands of network devices or servers over SSH protocol. The vSSH high-level API provides additional functionality for developing network or server automation. It supports persistent SSH connection to execute shell commands with a warm connection and returns data back quickly.</p><p>If you manage multiple Linux machines or devices you know how difficult it is to run commands on multiple machines every day, and appreciate the significant value of automation. There are other open source SSH libraries available in a variety of languages but vSSH has great features like persistent SSH connection, the ability to limit sessions, to limit the amount of data transferred, and it handles many SSH connections concurrently while using resources efficiently. Go developers can quickly create the network device, server automation, or tools, by using this library and focusing on the business logic instead of handling SSH connections.</p><figure data-orig-width="1463" data-orig-height="975" class="tmblr-full"><img src="https://66.media.tumblr.com/56840ccb434eea2e018e87531764f236/4a241c632ebe2a29-70/s540x810/4cfa974611c21105744d6f52ae9b0eb20ec1c130.png" alt="image" data-orig-width="1463" data-orig-height="975"/></figure><p>vSSH can run on your application asynchronous and then you can call the APIs/methods through your application (safe concurrency). To start, load your clients information and add them to vSSH using a simple method. You can add labels and other optional attributes to each client. By calling the run method, vSSH sends the given command to all available clients or based on your query, it runs the command on the specific clients and the results of the command can be received in streaming (real-time) or the final result.<br/></p><p>One of the main features of vSSH is a persistent connection to all devices and the ability to manage them. It can connect to all the configured devices/servers, all the time. The connections are simple authenticated connections without session at the first stage. When vSSH needs to run a command, it tries to create a session and it closes the session when it’s completed. If you don’t need the persistence feature then you can disable it, which results in the connection closing at the end. The main advantage of persistence is that it works as a warm connection and once the run command is requested, it just needs to create a session. The main use case is when you need to run commands on the clients continuously or the response time is important. In both cases, vSSH multiplexes sessions at one connection.</p><p>vSSH provides a DSL query feature based on the provided labels that you can use to select / filter clients. It supports operators like == != or you can also create your own logic. I wrote this feature with the Go abstract syntax tree (AST). This feature is very useful as you can add many clients to the library at the same time and run different commands based on the labels.</p><p>Here are three features that you can use to control the load on the client and force to terminate the running command:</p><ul><li>By limiting the returned data which comes from stdout or stderr in bytes</li>
<li>Terminate the command by defined timeout</li><li>Limit the concurrent sessions on the client<br/></li>
</ul><p><b>Use & Contribute</b></p><p>To learn more about vSSH, explore <a href="https://github.com/yahoo/vssh">github.com/yahoo/vssh</a> and try the vSSH examples at <a href="https://pkg.go.dev/github.com/yahoo/vssh">https://pkg.go.dev/github.com/yahoo/vssh</a>.</p>