Executing a command over SSH

Now that we have established multiple ways of authenticating and connecting to a remote SSH server, we need to put ssh.Client to work. So far we have only been printing out the client version. The first goal is to execute a single command and view the output.

Once ssh.Client is created, you can begin creating sessions. A client supports multiple sessions at once. A session has its own standard input, output, and error. They are standard reader and writer interfaces.

To execute a command there are a few options: Run(), Start(), Output(), and CombinedOutput(). They are all very similar, but behave a little differently:

  • session.Output(cmd): The Output() function will execute the command, and return session.Stdout ...

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.