Skip to content

Instantly share code, notes, and snippets.

@zxvdr zxvdr/ssh

Created Jan 2, 2014
Embed
What would you like to do?
SSH proxy
package main
import (
"bytes"
"code.google.com/p/go.crypto/ssh"
"fmt"
"log"
"net"
"os"
)
func main() {
// Passwordless authentication
sshsock := os.ExpandEnv("$SSH_AUTH_SOCK")
addr, _ := net.ResolveUnixAddr("unix", sshsock)
agentConn, _ := net.DialUnix("unix", nil, addr)
agent := ssh.NewAgentClient(agentConn)
config := &ssh.ClientConfig{
User: "example-user",
Auth: []ssh.ClientAuth{
ssh.ClientAuthAgent(agent),
},
}
fmt.Println("Dialing server B")
bastion, err := ssh.Dial("tcp", "server-b:22", config)
if err != nil {
panic("Failed to dial server B: " + err.Error())
}
defer bastion.Close()
fmt.Println("Dialing server C from server B")
bastionClient, err := bastion.Dial("tcp", "server-c:22")
if err != nil {
panic("Failed to dial server C from server B: " + err.Error())
}
defer bastionClient.Close()
fmt.Println("Handshaking server C from server B")
client, err := ssh.Client(bastionClient, config)
if err != nil {
panic("Failed to handshake server C from server B: " + err.Error())
}
defer client.Close()
// Create a session
fmt.Println("Session on server C")
session, err := client.NewSession()
if err != nil {
log.Fatalf("unable to create session: %s", err)
}
defer session.Close()
var stdErr, stdOut bytes.Buffer
session.Stdout = &stdOut
session.Stdout = &stdErr
fmt.Println("Running uptime on server C")
if err := session.Run("/usr/bin/uptime"); err != nil {
panic("Failed to run: " + err.Error())
}
fmt.Println(stdOut.String())
fmt.Println(stdErr.String())
}
@nullne

This comment has been minimized.

Copy link

nullne commented Feb 15, 2016

undefined: "code.google.com/p/go.crypto/ssh".NewAgentClient
Can your code run?

@DeadNumbers

This comment has been minimized.

Copy link

DeadNumbers commented Mar 16, 2016

@nullne golang.org/x/crypto/ssh

@colton22

This comment has been minimized.

Copy link

colton22 commented Mar 25, 2019

Still seeing an issue with NewAgentClient even after swapping the module to golang.org/x/crypto/ssh... was the function renamed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.