Using SSH in Go to Automate Remote Changes
Understand how to use SSH to automate remote changes in Go by using the Expect package.
We'll cover the following...
SSH is simply a network protocol that can be used to secure communication between two hosts.
While most people think that the ssh
binary allows us to connect from a terminal on one host to a terminal on another host, that is only one use. SSH can be used to secure connections for services such as Google Remote Procedure Call (gRPC) or to tunnel graphical interfaces such as the X Window System (X11).
Connecting to another system
The most basic use of SSH is to connect to another system and either send a single command or invoke a shell and issue commands. SSH is simply a transport mechanism, so there are many other uses of SSH such as connection tunneling or wrapping remote procedure calls (RPCs). We will not cover those here, as they are outside the use cases for general DevOps work.
As with most connection technologies, the hardest part of connecting to systems with an SSH client is resolving authentication. The most common forms of SSH authentication are outlined here:
Username/password: Username/password is the most popular implementation. It's the default and therefore the one that people tend to use. With network equipment, sometimes this is the only way. With this method, the password database may be on the local system, or the system may pass the password hash to another system to validate.
Public key authentication: Public key authentication is where a user creates a public/private key on their machine with an optional passphrase. The server has the public key installed for a user and our SSH client is set up to use the private key.
Challenge-response authentication: There are varying types of challenge-response authentication for SSH. This is commonly used to ...