Running multiple commands in one SSH session
<p>I need to run multiple commands in a single ssh session:</p>

<pre><code>// Define the client configuration
config := &amp;ssh.ClientConfig{
    User: USERNAME,
    Auth: []ssh.AuthMethod{
        ssh.PublicKeys(pem),
    },
}

// Connect to the machine
 client, err := ssh.Dial("tcp", HOSTNAME + ":" + PORT, config)
 if err != nil {
    panic("Failed to dial: " + err.Error())
}

// Create a session
session, err := client.NewSession()
if err != nil {
    panic("Failed to create session: " + err.Error())
}
defer session.Close()

// Start running commands!
var output bytes.Buffer
session.Stdout = &amp;output

// 1)  Login to swarm registry
fmt.Println("Logging into swarm registry...")
if err := session.Run("docker login ..."); err != nil {
    panic("Failed to login to swarm registry: " + err.Error())
}
fmt.Println(output.String())

// 2)  List all of the docker processes
fmt.Println("List swarm processes...")
if err := session.Run("docker ps"); err != nil {    // &lt;-------- FAILS HERE
    panic("Failed to list swarm processes: " + err.Error())
}
fmt.Println(output.String())
</code></pre>

<p>I read through the source file (<code>session.go</code>) and for the <code>Session.Run</code> command and it says:</p>

<blockquote>
  <p>A Session only accepts one call to Run, Start, Shell, Output, or CombinedOutput.</p>
</blockquote>

<p>For my use case I need to issue the first command to log the session in, and then issue subsequent commands once I am logged in.</p>

<p>Is there an alternate way to run multiple commands using the same ssh session?</p>