當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。