当前位置: 首页>>代码示例>>Golang>>正文


Golang ssh.Client函数代码示例

本文整理汇总了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
}
开发者ID:englishm,项目名称:packer,代码行数:32,代码来源:communicator.go

示例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
}
开发者ID:brianbrunner,项目名称:omg,代码行数:25,代码来源:test_unix_test.go

示例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)
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:28,代码来源:test_unix_test.go

示例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")
	}
}
开发者ID:kr,项目名称:runx,代码行数:35,代码来源:ssh_test.go

示例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
}
开发者ID:joscas,项目名称:sync_gateway,代码行数:26,代码来源:test_unix_test.go

示例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)
}
开发者ID:AsherBond,项目名称:cf-release,代码行数:25,代码来源:test_unix_test.go

示例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
}
开发者ID:reth-,项目名称:mole,代码行数:29,代码来源:ssh.go

示例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
}
开发者ID:kr,项目名称:sshpool,代码行数:17,代码来源:pool.go

示例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
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:20,代码来源:communicator.go

示例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
}
开发者ID:nashtsai,项目名称:go-netconf,代码行数:24,代码来源:transport_ssh.go

示例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
}
开发者ID:juju2013,项目名称:gsnova,代码行数:23,代码来源:ssh.go

示例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
}
开发者ID:Bobberino,项目名称:musings,代码行数:37,代码来源:test_unix_test.go

示例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
}
开发者ID:phobos182,项目名称:packer,代码行数:24,代码来源:communicator.go

示例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
}
开发者ID:tobert,项目名称:gdsh,代码行数:24,代码来源:connection.go

示例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
}
开发者ID:kyleconroy,项目名称:packer,代码行数:7,代码来源:communicator.go


注:本文中的code/google/com/p/go/crypto/ssh.Client函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。