Golang code-google-com-p-go-crypto-ssh.ClientAuthPassword类(方法)实例源码

下面列出了Golang code-google-com-p-go-crypto-ssh.ClientAuthPassword 类(方法)源码代码实例,从而了解它的用法。

作者:reth    项目:mol   
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
}

作者:EdevMosai    项目:packe   
func (d *ESX5Driver) connect() error {
	address := fmt.Sprintf("%s:%d", d.Host, d.Port)

	auth := []gossh.ClientAuth{
		gossh.ClientAuthPassword(ssh.Password(d.Password)),
		gossh.ClientAuthKeyboardInteractive(
			ssh.PasswordKeyboardInteractive(d.Password)),
	}

	// TODO(dougm) KeyPath support
	sshConfig := &ssh.Config{
		Connection: ssh.ConnectFunc("tcp", address),
		SSHConfig: &gossh.ClientConfig{
			User: d.Username,
			Auth: auth,
		},
		NoPty: true,
	}

	comm, err := ssh.New(sshConfig)
	if err != nil {
		return err
	}

	d.comm = comm
	return nil
}

作者:EdevMosai    项目:packe   
func TestNew_Invalid(t *testing.T) {
	clientConfig := &ssh.ClientConfig{
		User: "user",
		Auth: []ssh.ClientAuth{
			ssh.ClientAuthPassword(password("i-am-invalid")),
		},
	}

	conn := func() (net.Conn, error) {
		conn, err := net.Dial("tcp", newMockLineServer(t))
		if err != nil {
			t.Fatalf("unable to dial to remote side: %s", err)
		}
		return conn, err
	}

	config := &Config{
		Connection: conn,
		SSHConfig:  clientConfig,
	}

	_, err := New(config)
	if err == nil {
		t.Fatal("should have had an error connecting")
	}
}

作者:EdevMosai    项目:packe   
func TestStart(t *testing.T) {
	clientConfig := &ssh.ClientConfig{
		User: "user",
		Auth: []ssh.ClientAuth{
			ssh.ClientAuthPassword(password("pass")),
		},
	}

	conn := func() (net.Conn, error) {
		conn, err := net.Dial("tcp", newMockLineServer(t))
		if err != nil {
			t.Fatalf("unable to dial to remote side: %s", err)
		}
		return conn, err
	}

	config := &Config{
		Connection: conn,
		SSHConfig:  clientConfig,
	}

	client, err := New(config)
	if err != nil {
		t.Fatalf("error connecting to SSH: %s", err)
	}

	var cmd packer.RemoteCmd
	stdout := new(bytes.Buffer)
	cmd.Command = "echo foo"
	cmd.Stdout = stdout

	client.Start(&cmd)
}

作者:pavel-paula    项目:mobile_per   
func (h *RemoteHelper) Init(username, password string) {
	h.config = &ssh.ClientConfig{
		User: username,
		Auth: []ssh.ClientAuth{
			ssh.ClientAuthPassword(clientPassword(password)),
		},
	}
}

作者:nashtsa    项目:go-netcon   
// SSHConfigPassword is a convience function that takes a username and password
// and returns a new ssh.ClientConfig setup to pass that username and password.
func SSHConfigPassword(user string, pass string) *ssh.ClientConfig {
	return &ssh.ClientConfig{
		User: user,
		Auth: []ssh.ClientAuth{
			ssh.ClientAuthPassword(simpleSSHPassword(pass)),
		},
	}
}

作者:yinwer8    项目:haproxyconsol   
func ScpHaproxyConf(appConf config.ConfigInfo) (errinfo error) {

	server := fmt.Sprintf("%s:%d", appConf.SlaveServerIp, appConf.SlaveServerSSHPort)
	username := appConf.SlaveRemoteUser
	password := clientPassword(appConf.SlaveRemotePasswd)

	// An SSH client is represented with a slete). Currently only
	// the "password" authentication method is supported.
	//
	// To authenticate with the remote server you must pass at least one
	// implementation of ClientAuth via the Auth field in ClientConfig.

	conf := &ssh.ClientConfig{
		User: username,
		Auth: []ssh.ClientAuth{
			// ClientAuthPassword wraps a ClientPassword implementation
			// in a type that implements ClientAuth.
			ssh.ClientAuthPassword(password),
		},
	}
	client, err := ssh.Dial("tcp", server, conf)
	if err != nil {
		errinfo = errors.New(fmt.Sprintf("Failed to dial: %s", err.Error()))
		return
	}

	// Each ClientConn can support multiple interactive sessions,
	// represented by a Session.
	defer client.Close()
	// Create a session
	session, err := client.NewSession()
	if err != nil {
		errinfo = errors.New(fmt.Sprintf("unable to create session: %s", err.Error()))
		return
	}
	defer session.Close()

	confBytes, err := ioutil.ReadFile(appConf.NewHAProxyConfPath)
	if err != nil {
		errinfo = errors.New(fmt.Sprintf("Failed to run: %s", err.Error()))
		return
	}
	content := string(confBytes)
	go func() {
		w, _ := session.StdinPipe()
		defer w.Close()
		fmt.Fprintln(w, "C0644", len(content), "new_conf")
		fmt.Fprint(w, content)
		fmt.Fprint(w, "\x00")
	}()
	cmd := fmt.Sprintf("%s -tq %s && %s", appConf.ScpCommandPath, appConf.SlaveConf, appConf.SlaveRestartScript)
	if err := session.Run(cmd); err != nil {
		errinfo = errors.New(fmt.Sprintf("Failed to run: %s", err.Error()))
		return
	}
	return
}

作者:davechene    项目:websomte   
func main() {
	flag.Parse()

	config := &ssh.ClientConfig{
		User: *sshuser,
		Auth: []ssh.ClientAuth{
			ssh.ClientAuthPassword(password(*sshpass)),
		},
	}
	conn, err := ssh.Dial("tcp", *sshhost+":22", config)
	if err != nil {
		log.Fatalf("unable to connect: %s", err)
	}

	log.Println("connected to ssh server")
	defer conn.Close()

	http.HandleFunc("/", home)
	if *debug {
		http.HandleFunc("/resend", resend)
	}
	http.Handle("/stream", websocket.Handler(streamMail))

	sln, err := conn.Listen("tcp", *smtpListen)
	if err != nil {
		log.Fatalf("error listening for SMTP: %v", err)
	}

	hln, err := conn.Listen("tcp", *webListen)
	if err != nil {
		log.Fatalf("error listening for HTTP: %v", err)
	}
	log.Printf("websomtep listening for HTTP on %q and SMTP on %q\n", *webListen, *smtpListen)
	go http.Serve(hln, nil)

	s := &smtpd.Server{
		OnNewMail: func(c smtpd.Connection, from smtpd.MailAddress) (smtpd.Envelope, error) {
			log.Printf("New message from %q", from)
			e := &Message{
				From: from.Email(),
			}
			return e, nil
		},
	}

	smtpCountListener := &countingListener{
		Listener: sln,
		fn: func(count int) {
			broadcast(&Message{msg: &SMTPStat{NumSenders: count}})
		},
	}

	err = s.Serve(smtpCountListener)
	if err != nil {
		log.Fatalf("ListenAndServe: %v", err)
	}
}

作者:postfi    项目:sshclien   
func exec(server, username, password, cmd string, c chan Results) {
	// To authenticate with the remote server you must pass at least one
	// implementation of ClientAuth via the Auth field in ClientConfig.
	// Currently only the "password" authentication method is supported.

	config := &ssh.ClientConfig{
		User: username,
		Auth: []ssh.ClientAuth{
			// ClientAuthPassword wraps a ClientPassword implementation
			// in a type that implements ClientAuth.
			ssh.ClientAuthPassword(clientPassword(password)),
		},
	}
	client, err := ssh.Dial("tcp", server, config)
	if err != nil {
		err = errors.New("Failed to dial: " + err.Error())
		c <- Results{err: err}
		return
	}

	// Each ClientConn can support multiple interactive sessions,
	// represented by a Session.
	defer client.Close()

	// Create a session
	session, err := client.NewSession()
	if err != nil {
		c <- Results{err: err}
		return
	}
	defer session.Close()

	// Set up terminal modes
	modes := ssh.TerminalModes{
		ssh.ECHO:          0,     // disable echoing
		ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud
		ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud
	}
	// Request pseudo terminal
	if err := session.RequestPty("xterm", 80, 40, modes); err != nil {
		err := errors.New("request for pseudo terminal failed: " + err.Error())
		c <- Results{err: err}
		return
	}

	var stdout, stderr bytes.Buffer
	session.Stdout = &stdout
	session.Stderr = &stderr
	rc := 0
	if err := session.Run(cmd); err != nil {
		if ugh, ok := err.(*ssh.ExitError); ok {
			rc = ugh.Waitmsg.ExitStatus()
		}
	}
	c <- Results{nil, rc, stdout.String(), stderr.String()}
}

作者:postfi    项目:waSS   
func Connect(server string, user string, pwd string) (*ssh.ClientConn, error) {
	config := &ssh.ClientConfig{
		User: user,
		Auth: []ssh.ClientAuth{
			ssh.ClientAuthPassword(clientPassword(pwd)),
			//TODO ssh.ClientAuthKeyring(clientKey),
		},
	}
	return ssh.Dial("tcp", server, config)
}

作者:robinbowe    项目:packe   
func sshConfig(state map[string]interface{}) (*gossh.ClientConfig, error) {
	config := state["config"].(*config)

	return &gossh.ClientConfig{
		User: config.SSHUser,
		Auth: []gossh.ClientAuth{
			gossh.ClientAuthPassword(ssh.Password(config.SSHPassword)),
			gossh.ClientAuthKeyboardInteractive(
				ssh.PasswordKeyboardInteractive(config.SSHPassword)),
		},
	}, nil
}

作者:jaypalominod    项目:troussea   
func (ss *ScpStorage) Connect() error {
	var err error

	clientConfig := &ssh.ClientConfig{
		User: ss.User,
		Auth: []ssh.ClientAuth{
			ssh.ClientAuthPassword(password(ss.Password)),
			ssh.ClientAuthKeyring(ss.Keychain),
		},
	}

	ss.connexion, err = ssh.Dial("tcp", ss.Endpoint, clientConfig)
	if err != nil {
		return fmt.Errorf("Failed to dial: %s", err.Error())
	}

	return nil
}

作者:zbrdg    项目:remember-m   
func main() {

	fmt.Printf("Please enter a username: ")
	reader := bufio.NewReader(os.Stdin)
	username, _ := reader.ReadString('\n')
	username = strings.TrimSpace(username)

	// An SSH client is represented with a ClientConn. Currently only
	// the "password" authentication method is supported.
	//
	// To authenticate with the remote server you must pass at least one
	// implementation of ClientAuth via the Auth field in ClientConfig.
	config := &ssh.ClientConfig{
		User: username,
		Auth: []ssh.ClientAuth{
			// ClientAuthPassword wraps a ClientPassword implementation
			// in a type that implements ClientAuth.
			ssh.ClientAuthPassword(userPass(username)),
		},
	}

	client, err := ssh.Dial("tcp", server+":22", config)
	if err != nil {
		panic("Failed to dial: " + err.Error())
	}

	// Each ClientConn can support multiple interactive sessions,
	// represented by a Session.
	session, err := client.NewSession()
	if err != nil {
		panic("Failed to create session: " + err.Error())
	}
	defer session.Close()

	// Once a Session is created, you can execute a single command on
	// the remote side using the Run method.
	var b bytes.Buffer
	session.Stdout = &b
	if err := session.Run("/usr/bin/uname"); err != nil {
		panic("Failed to run: " + err.Error())
	}

	fmt.Println(b.String())
}

作者:carriercom    项目:sky-   
// SSH logic
func (c *SSHConn) Connect(host, user string) error {
	c.host = host
	c.user = user

	config := &ssh.ClientConfig{
		User: c.user,
		Auth: []ssh.ClientAuth{
			ssh.ClientAuthPassword(c),
		},
	}

	var err error
	c.client, err = ssh.Dial("tcp", c.host, config)
	if err != nil {
		return err
	}

	return nil
}

作者:davechene    项目:sshsmas   
func main() {
	config := &ssh.ClientConfig{
		User: *USER,
		Auth: []ssh.ClientAuth{
			ssh.ClientAuthPassword(password(*PASS)),
		},
	}

	log.Println("Starting ... ")
	t1 := time.Now()
	var conns sync.WaitGroup
	conns.Add(*CONNS)
	for i := 0; i < *CONNS; i++ {
		go startConn(config, &conns)
	}
	conns.Wait()
	t2 := time.Since(t1)
	log.Printf("Test duration %v", t2)
}

作者:hosange    项目:al   
// Connect implements the ssh connection phase
func (c *HostConnection) connect() error {
	c.connectionMutex.Lock()
	if c.connection == nil {
		config := &ssh.ClientConfig{
			User: c.Host.Username,
			Auth: []ssh.ClientAuth{
				ssh.ClientAuthPassword(password(c.Host.Password)),
			},
		}
		var err error
		url := c.Host.Hostname + ":" + strconv.Itoa(c.Host.Port)
		c.connection, err = ssh.Dial("tcp", url, config)
		if err != nil {
			return err
		}
	}
	c.connectionMutex.Unlock()
	return nil
}

作者:willemvd    项目:T   
func doSSH(c chan *ssh.Session, sship string, username string, pw password) {
	config := &ssh.ClientConfig{
		User: username,
		Auth: []ssh.ClientAuth{
			ssh.ClientAuthPassword(pw),
		},
	}
	client, err := ssh.Dial("tcp", sship, config)
	if err != nil {
		panic("Failed to dial: " + err.Error())
	}

	session, err := client.NewSession()
	if err != nil {
		panic("Failed to create session: " + err.Error())
	}
	c <- session

	stdout, err := session.StdoutPipe()
	if err != nil {
		fmt.Println(err)
	}
	ccout <- &stdout

	stderr, err := session.StderrPipe()
	if err != nil {
		fmt.Println(err)
	}
	ccerr <- &stderr

	stdin, err := session.StdinPipe()
	if err != nil {
		fmt.Println(err)
	}
	ccin <- &stdin

	if err := session.Shell(); err != nil {
		fmt.Println(err)
	}
}

作者:davechene    项目:http-over-ssh-exampl   
func main() {
	config := &ssh.ClientConfig{
		User: *sshuser,
		Auth: []ssh.ClientAuth{
			ssh.ClientAuthPassword(password(*sshpass)),
		},
	}
	conn, err := ssh.Dial("tcp", "localhost:22", config)
	if err != nil {
		log.Fatalf("unable to connect: %s", err)
	}
	defer conn.Close()

	l, err := conn.Listen("tcp", "0.0.0.0:8080")
	if err != nil {
		log.Fatalf("unable to register tcp forward: %v", err)
	}
	defer l.Close()
	http.Serve(l, http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
		fmt.Fprintf(resp, "Hello world!\n")
	}))
}

作者:B-Ric    项目:packe   
func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) {
	config := state.Get("config").(*config)

	auth := []gossh.ClientAuth{
		gossh.ClientAuthPassword(ssh.Password(config.SSHPassword)),
		gossh.ClientAuthKeyboardInteractive(
			ssh.PasswordKeyboardInteractive(config.SSHPassword)),
	}

	if config.SSHKeyPath != "" {
		keyring, err := sshKeyToKeyring(config.SSHKeyPath)
		if err != nil {
			return nil, err
		}

		auth = append(auth, gossh.ClientAuthKeyring(keyring))
	}

	return &gossh.ClientConfig{
		User: config.SSHUser,
		Auth: auth,
	}, nil
}

作者:joy99    项目:goss   
func (c *Client) Connect() (e error) {
	if c.Port == 0 {
		c.Port = 22
	}
	var auths []ssh.ClientAuth

	if c.password != "" {
		auths = append(auths, ssh.ClientAuthPassword(c))
	}

	if c.Agent, e = net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); e == nil {
		auths = append(auths, ssh.ClientAuthAgent(ssh.NewAgentClient(c.Agent)))
	}

	config := &ssh.ClientConfig{
		User: c.User,
		Auth: auths,
	}
	c.Conn, e = ssh.Dial("tcp", fmt.Sprintf("%s:%d", c.Host, c.Port), config)
	if e != nil {
		return e
	}
	return nil
}


问题


面经


文章

微信
公众号

扫码关注公众号