本文整理匯總了Golang中code/google/com/p/go/crypto/ssh.Client函數的典型用法代碼示例。如果您正苦於以下問題:Golang Client函數的具體用法?Golang Client怎麽用?Golang Client使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Client函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: reconnect
func (c *comm) reconnect() (err error) {
if c.conn != nil {
c.conn.Close()
}
// Set the conn and client to nil since we'll recreate it
c.conn = nil
c.client = nil
log.Printf("reconnecting to TCP connection for SSH")
c.conn, err = c.config.Connection()
if err != nil {
// Explicitly set this to the REAL nil. Connection() can return
// a nil implementation of net.Conn which will make the
// "if c.conn == nil" check fail above. Read here for more information
// on this psychotic language feature:
//
// http://golang.org/doc/faq#nil_error
c.conn = nil
log.Printf("reconnection error: %s", err)
return
}
log.Printf("handshaking with SSH")
c.client, err = ssh.Client(c.conn, c.config.SSHConfig)
if err != nil {
log.Printf("handshake error: %s", err)
}
return
}
示例2: Dial
func (s *server) Dial(config *ssh.ClientConfig) *ssh.ClientConn {
s.cmd = exec.Command("sshd", "-f", s.configfile, "-i")
stdin, err := s.cmd.StdinPipe()
if err != nil {
s.t.Fatal(err)
}
stdout, err := s.cmd.StdoutPipe()
if err != nil {
s.t.Fatal(err)
}
s.cmd.Stderr = os.Stderr // &s.output
err = s.cmd.Start()
if err != nil {
s.t.FailNow()
s.Shutdown()
s.t.Fatal(err)
}
conn, err := ssh.Client(&client{stdin, stdout}, config)
if err != nil {
s.t.FailNow()
s.Shutdown()
s.t.Fatal(err)
}
return conn
}
示例3: TryDial
func (s *server) TryDial(config *ssh.ClientConfig) (*ssh.ClientConn, error) {
sshd, err := exec.LookPath("sshd")
if err != nil {
s.t.Skipf("skipping test: %v", err)
}
c1, c2, err := unixConnection()
if err != nil {
s.t.Fatalf("unixConnection: %v", err)
}
s.cmd = exec.Command(sshd, "-f", s.configfile, "-i", "-e")
f, err := c2.File()
if err != nil {
s.t.Fatalf("UnixConn.File: %v", err)
}
defer f.Close()
s.cmd.Stdin = f
s.cmd.Stdout = f
s.cmd.Stderr = &s.output
if err := s.cmd.Start(); err != nil {
s.t.Fail()
s.Shutdown()
s.t.Fatalf("s.cmd.Start: %v", err)
}
s.clientConn = c1
return ssh.Client(c1, config)
}
示例4: TestSSHD
func TestSSHD(t *testing.T) {
block, _ := pem.Decode([]byte(testClientPrivateKey))
rsakey, _ := x509.ParsePKCS1PrivateKey(block.Bytes)
pub, _ := ssh.NewPublicKey(&rsakey.PublicKey)
cmd, c, err := startSSHD(ssh.MarshalAuthorizedKey(pub))
if err != nil {
t.Fatal(err)
}
defer cmd.Wait()
defer cmd.Process.Kill()
u, err := user.Current()
if err != nil {
t.Fatal(err)
}
_ = u
config := &ssh.ClientConfig{
User: u.Username,
Auth: []ssh.ClientAuth{ssh.ClientAuthKeyring(&keyring{rsakey})},
}
client, err := ssh.Client(c, config)
if err != nil {
t.Fatal(err)
}
sess, err := client.NewSession()
if err != nil {
t.Fatal(err)
}
out, err := sess.Output("echo hello")
if err != nil {
t.Fatal(err)
}
if string(out) != "hello\n" {
t.Fatalf("out = %q want %q", string(out), "hello\n")
}
}
示例5: Dial
func (s *server) Dial(config *ssh.ClientConfig) *ssh.ClientConn {
s.cmd = exec.Command("sshd", "-f", s.configfile, "-i")
r1, w1, err := os.Pipe()
if err != nil {
s.t.Fatal(err)
}
s.cmd.Stdout = w1
r2, w2, err := os.Pipe()
if err != nil {
s.t.Fatal(err)
}
s.cmd.Stdin = r2
s.cmd.Stderr = os.Stderr
if err := s.cmd.Start(); err != nil {
s.t.Fail()
s.Shutdown()
s.t.Fatalf("s.cmd.Start: %v", err)
}
conn, err := ssh.Client(&client{wc: w2, r: r1}, config)
if err != nil {
s.t.Fail()
s.Shutdown()
s.t.Fatalf("ssh.Client: %v", err)
}
return conn
}
示例6: TryDial
func (s *server) TryDial(config *ssh.ClientConfig) (*ssh.ClientConn, error) {
sshd, err := exec.LookPath("sshd")
if err != nil {
s.t.Skipf("skipping test: %v", err)
}
s.cmd = exec.Command(sshd, "-f", s.configfile, "-i", "-e")
r1, w1, err := os.Pipe()
if err != nil {
s.t.Fatal(err)
}
s.cmd.Stdout = w1
r2, w2, err := os.Pipe()
if err != nil {
s.t.Fatal(err)
}
s.cmd.Stdin = r2
s.cmd.Stderr = os.Stderr
if err := s.cmd.Start(); err != nil {
s.t.Fail()
s.Shutdown()
s.t.Fatalf("s.cmd.Start: %v", err)
}
return ssh.Client(&client{wc: w2, r: r1}, config)
}
示例7: sshOnConn
func sshOnConn(conn net.Conn, h conf.Host) (*ssh.ClientConn, error) {
var auths []ssh.ClientAuth
if h.Pass != "" {
auths = append(auths, ssh.ClientAuthPassword(password(h.Pass)))
auths = append(auths, ssh.ClientAuthKeyboardInteractive(challenge(h.Pass)))
}
if h.Key != "" {
k := &keyring{}
err := k.loadPEM([]byte(h.Key))
if err != nil {
return nil, err
}
auths = append(auths, ssh.ClientAuthKeyring(k))
}
config := &ssh.ClientConfig{
User: h.User,
Auth: auths,
}
debugln("handshake & authenticate")
client, err := ssh.Client(conn, config)
if err != nil {
return nil, err
}
return client, nil
}
示例8: dial
func (p *Pool) dial(network, addr string, config *ssh.ClientConfig, deadline time.Time) (net.Conn, *ssh.ClientConn, error) {
dial := p.Dial
if dial == nil {
dialer := net.Dialer{Deadline: deadline}
dial = dialer.Dial
}
netC, err := dial(network, addr)
if err != nil {
return nil, nil, err
}
sshC, err := ssh.Client(netC, config)
if err != nil {
netC.Close()
return nil, nil, err
}
return netC, sshC, nil
}
示例9: reconnect
func (c *comm) reconnect() (err error) {
if c.conn != nil {
c.conn.Close()
}
log.Printf("reconnecting to TCP connection for SSH")
c.conn, err = c.config.Connection()
if err != nil {
log.Printf("reconnection error: %s", err)
return
}
log.Printf("handshaking with SSH")
c.client, err = ssh.Client(c.conn, c.config.SSHConfig)
if err != nil {
log.Printf("handshake error: %s", err)
}
return
}
示例10: DialSSHWithAddress
// Create a new NETCONF session using an existing net.Conn.
func DialSSHWithAddress(conn *net.Conn, config *ssh.ClientConfig) (*Session, error) {
var (
t TransportSSH
err error
)
t.sshConn, err = ssh.Client(*conn, config)
if err != nil {
return nil, err
}
err = t.setSessionAndPipes()
if err != nil {
return nil, err
}
err = t.requestNetconfSubsystem()
if err != nil {
return nil, err
}
return NewSession(&t), nil
}
示例11: GetClientConn
func (conn *SSHRawConnection) GetClientConn(reconnect bool) (*ssh.ClientConn, error) {
if !reconnect && nil != conn.clientConn {
return conn.clientConn, nil
} else {
if nil != conn.clientConn {
conn.clientConn.Close()
}
conn.clientConn = nil
dial := net.Dial
if nil != sshLocalProxy {
dial = func(network, addr string) (net.Conn, error) {
return util.HttpTunnelDial(network, addr, sshLocalProxy)
}
}
if c, err := dial("tcp", conn.Server); nil != err {
return nil, err
} else {
conn.clientConn, err = ssh.Client(c, conn.ClientConfig)
return conn.clientConn, err
}
}
return nil, nil
}
示例12: Dial
func (s *server) Dial() *ssh.ClientConn {
s.cmd = exec.Command("sshd", "-f", s.configfile, "-i")
stdin, err := s.cmd.StdinPipe()
if err != nil {
s.t.Fatal(err)
}
stdout, err := s.cmd.StdoutPipe()
if err != nil {
s.t.Fatal(err)
}
s.cmd.Stderr = os.Stderr
err = s.cmd.Start()
if err != nil {
s.Shutdown()
s.t.Fatal(err)
}
user, err := user.Current()
if err != nil {
s.Shutdown()
s.t.Fatal(err)
}
kc := new(keychain)
kc.keys = append(kc.keys, rsakey)
config := &ssh.ClientConfig{
User: user.Username,
Auth: []ssh.ClientAuth{
ssh.ClientAuthKeyring(kc),
},
}
conn, err := ssh.Client(&client{stdin, stdout}, config)
if err != nil {
s.Shutdown()
s.t.Fatal(err)
}
return conn
}
示例13: reconnect
func (c *comm) reconnect() (err error) {
if c.conn != nil {
c.conn.Close()
}
// Set the conn and client to nil since we'll recreate it
c.conn = nil
c.client = nil
log.Printf("reconnecting to TCP connection for SSH")
c.conn, err = c.config.Connection()
if err != nil {
log.Printf("reconnection error: %s", err)
return
}
log.Printf("handshaking with SSH")
c.client, err = ssh.Client(c.conn, c.config.SSHConfig)
if err != nil {
log.Printf("handshake error: %s", err)
}
return
}
示例14: connect
func (conn *Conn) connect() (err error) {
if conn.connected {
panic("BUG: connect() called on connected socket/client!")
}
// dial manually so the tcp socket can be closed directly since it's hidden
// if you use ssh.Dial, might also be handy for tuning?
conn.netconn, err = net.Dial("tcp", conn.address)
if err != nil {
conn.connected = false
return
}
conn.client, err = ssh.Client(conn.netconn, conn.config)
if err != nil {
conn.connected = false
return
}
conn.Started = time.Now()
conn.connected = true
return
}
示例15: New
// Creates a new packer.Communicator implementation over SSH. This takes
// an already existing TCP connection and SSH configuration.
func New(c net.Conn, config *ssh.ClientConfig) (result *comm, err error) {
client, err := ssh.Client(c, config)
result = &comm{client}
return
}