• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ssh.Password函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中golang.org/x/crypto/ssh.Password函数的典型用法代码示例。如果您正苦于以下问题:Golang Password函数的具体用法?Golang Password怎么用?Golang Password使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Password函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: makeConfig

func makeConfig(user string, password string, privateKey string) (config *ssh.ClientConfig) {

	if password == "" && user == "" {
		log.Fatal("No password or private key available")
	}
	config = &ssh.ClientConfig{
		User: user,
		Auth: []ssh.AuthMethod{
			ssh.Password(password),
		},
	}
	if privateKey != "" {
		log.Println(privateKey)
		signer, err := ssh.ParsePrivateKey([]byte(privateKey))
		if err != nil {
			log.Fatalf("ssh.ParsePrivateKey error:%v", err)
		}
		clientkey := ssh.PublicKeys(signer)
		config = &ssh.ClientConfig{
			User: user,
			Auth: []ssh.AuthMethod{
				clientkey,
			},
		}
	}
	return
}
开发者ID:Gooooodman,项目名称:gosshtool,代码行数:27,代码来源:common.go


示例2: main

func main() {
	if len(os.Args) != 5 {
		fmt.Fprintf(os.Stderr, "Usage: %s <host> <username> <password> <remote name>\n",
			os.Args[0])
		os.Exit(1)
	}

	conn, err := sshcp.NewConn(
		os.Args[1],
		os.Args[2],
		os.Args[4],
		ssh.Password(os.Args[3]),
	)
	if err != nil {
		fmt.Fprintf(os.Stderr, "could not open connection: %s", err)
		return
	}
	defer conn.Close()

	_, err = io.Copy(conn, os.Stdin)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error copying data: %s", err)
		return
	}

	fmt.Fprintln(os.Stderr, "done")
}
开发者ID:andrew-d,项目名称:sshcp,代码行数:27,代码来源:simple.go


示例3: NewNativeConfig

func NewNativeConfig(user string, auth *Auth) (ssh.ClientConfig, error) {
	var (
		authMethods []ssh.AuthMethod
	)

	for _, k := range auth.Keys {
		key, err := ioutil.ReadFile(k)
		if err != nil {
			return ssh.ClientConfig{}, err
		}

		privateKey, err := ssh.ParsePrivateKey(key)
		if err != nil {
			return ssh.ClientConfig{}, err
		}

		authMethods = append(authMethods, ssh.PublicKeys(privateKey))
	}

	for _, p := range auth.Passwords {
		authMethods = append(authMethods, ssh.Password(p))
	}

	return ssh.ClientConfig{
		User: user,
		Auth: authMethods,
	}, nil
}
开发者ID:jkingyens,项目名称:machine,代码行数:28,代码来源:client.go


示例4: ExampleSession_RequestPty

func ExampleSession_RequestPty() {
	// Create client config
	config := &ssh.ClientConfig{
		User: "username",
		Auth: []ssh.AuthMethod{
			ssh.Password("password"),
		},
	}
	// Connect to ssh server
	conn, err := ssh.Dial("tcp", "localhost:22", config)
	if err != nil {
		log.Fatalf("unable to connect: %s", err)
	}
	defer conn.Close()
	// Create a session
	session, err := conn.NewSession()
	if err != nil {
		log.Fatalf("unable to create session: %s", err)
	}
	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 {
		log.Fatalf("request for pseudo terminal failed: %s", err)
	}
	// Start remote shell
	if err := session.Shell(); err != nil {
		log.Fatalf("failed to start shell: %s", err)
	}
}
开发者ID:CodeJuan,项目名称:deis,代码行数:35,代码来源:example_test.go


示例5: connect

// connects to remote server using ClientSSH struct and returns *ssh.Session
func (ssh_conf *ClientSSH) connect() (*ssh.Session, error) {
	// auths holds the detected ssh auth methods
	auths := []ssh.AuthMethod{}

	// figure out what auths are requested, what is supported
	if ssh_conf.Password != "" {
		auths = append(auths, ssh.Password(ssh_conf.Password))
	}

	if sshAgent, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); err == nil {
		auths = append(auths, ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers))
		defer sshAgent.Close()
	}

	if pubkey, err := getKeyFile(ssh_conf.Key); err == nil {
		auths = append(auths, ssh.PublicKeys(pubkey))
	}

	config := &ssh.ClientConfig{
		User: ssh_conf.User,
		Auth: auths,
	}

	client, err := ssh.Dial("tcp", ssh_conf.Server+":"+ssh_conf.Port, config)
	if err != nil {
		return nil, err
	}

	session, err := client.NewSession()
	if err != nil {
		return nil, err
	}

	return session, nil
}
开发者ID:rootless4real,项目名称:musicsaur,代码行数:36,代码来源:ssh.go


示例6: TestHandshakeTimeout

func TestHandshakeTimeout(t *testing.T) {
	clientConfig := &ssh.ClientConfig{
		User: "user",
		Auth: []ssh.AuthMethod{
			ssh.Password("pass"),
		},
	}

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

	config := &Config{
		Connection:       conn,
		SSHConfig:        clientConfig,
		HandshakeTimeout: 50 * time.Millisecond,
	}

	_, err := New(address, config)
	if err != ErrHandshakeTimeout {
		// Note: there's another error that can come back from this call:
		//   ssh: handshake failed: EOF
		// This should appear in cases where the handshake fails because of
		// malformed (or no) data sent back by the server, but should not happen
		// in a timeout scenario.
		t.Fatalf("Expected handshake timeout, got: %s", err)
	}
}
开发者ID:c12simple,项目名称:packer,代码行数:33,代码来源:communicator_test.go


示例7: ExampleDial

func ExampleDial() {
	// 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 AuthMethod via the Auth field in ClientConfig.
	config := &ssh.ClientConfig{
		User: "username",
		Auth: []ssh.AuthMethod{
			ssh.Password("yourpassword"),
		},
	}
	client, err := ssh.Dial("tcp", "yourserver.com: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/whoami"); err != nil {
		panic("Failed to run: " + err.Error())
	}
	fmt.Println(b.String())
}
开发者ID:CodeJuan,项目名称:deis,代码行数:34,代码来源:example_test.go


示例8: TestHandlerError

func (suite *ServerSuite) TestHandlerError() {

	// Configure client connection
	config := &ssh.ClientConfig{
		User: "jonny.quest",
		Auth: []ssh.AuthMethod{
			ssh.Password("bandit"),
		},
	}

	// Create client connection
	client, err := ssh.Dial("tcp", "127.0.0.1:9022", config)
	if err != nil {
		suite.Fail(err.Error())
		return
	}
	defer client.Close()

	// Open channel
	channel, requests, err := client.OpenChannel("/bad", []byte{})
	if err != nil {
		suite.Fail(err.Error())
		return
	}
	go ssh.DiscardRequests(requests)
	defer channel.Close()
}
开发者ID:blacklabeldata,项目名称:sshh,代码行数:27,代码来源:server_test.go


示例9: DownLoadDirectoryRecurrsively

func DownLoadDirectoryRecurrsively(hostAndPort string, username string,
	password string, remoteSourceDirectory string, localTargetDirectory string) error {

	remoteSourceDirectoryLength := len(remoteSourceDirectory)

	authMethodSlice := make([]ssh.AuthMethod, 0)
	authMethodSlice = append(authMethodSlice, ssh.Password(password))

	clientConfig := ssh.ClientConfig{
		User: username,
		Auth: authMethodSlice,
	}
	connection, err := ssh.Dial("tcp", hostAndPort, &clientConfig)
	if err != nil {
		return err
	}
	defer connection.Close()

	// open an SFTP session over an existing ssh connection.
	client, err := sftp.NewClient(connection)
	if err != nil {
		return err
	}
	defer client.Close()

	// walk a directory
	walk := client.Walk(remoteSourceDirectory)
	for walk.Step() {
		if err := walk.Err(); err != nil {
			return err
		}

		if walk.Stat().IsDir() {
			directoryPath := localTargetDirectory + walk.Path()[remoteSourceDirectoryLength:]
			if err := os.MkdirAll(directoryPath, os.ModePerm); err != nil {
				return err
			}
		} else {
			filePath := localTargetDirectory + walk.Path()[remoteSourceDirectoryLength:]
			file, err := client.Open(walk.Path())
			if err != nil {
				return err
			}
			defer file.Close()

			outputFile, err := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY, os.ModePerm)
			if err != nil {
				return err
			}
			defer outputFile.Close()

			_, err = file.WriteTo(outputFile)
			if err != nil {
				return err
			}
		}
	}

	return nil
}
开发者ID:cloudawan,项目名称:cloudone_utility,代码行数:60,代码来源:sftp_client.go


示例10: sshConfig

func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) {
	config := state.Get("config").(*Config)
	var privateKey string

	var auth []gossh.AuthMethod

	if config.Comm.SSHPassword != "" {
		auth = []gossh.AuthMethod{
			gossh.Password(config.Comm.SSHPassword),
			gossh.KeyboardInteractive(
				ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)),
		}
	}

	if config.Comm.SSHPrivateKey != "" {
		if priv, ok := state.GetOk("privateKey"); ok {
			privateKey = priv.(string)
		}
		signer, err := gossh.ParsePrivateKey([]byte(privateKey))
		if err != nil {
			return nil, fmt.Errorf("Error setting up SSH config: %s", err)
		}
		if err != nil {
			return nil, err
		}

		auth = append(auth, gossh.PublicKeys(signer))
	}
	return &gossh.ClientConfig{
		User: config.Comm.SSHUsername,
		Auth: auth,
	}, nil
}
开发者ID:arizvisa,项目名称:packer,代码行数:33,代码来源:ssh.go


示例11: main

func main() {

	config := &ssh.ClientConfig{
		User: "meuUsuario",
		Auth: []ssh.AuthMethod{
			ssh.Password("minhaSenha"),
		},
	}

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

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

	defer session.Close()

	var b bytes.Buffer
	session.Stdout = &b
	if err := session.Run("/usr/bin/whoami"); err != nil {
		panic("Failed to run: " + err.Error())
	}
	fmt.Println(b.String())
}
开发者ID:viliamjr,项目名称:lab,代码行数:28,代码来源:sshClient.go


示例12: Connect

func (S *SshParm) Connect() (*ssh.Client, error) {
	var (
		cfg *ssh.ClientConfig
	)

	if S.SSHAuthType == SSHAuthType_Certificate {
		cfg = &ssh.ClientConfig{
			User: S.SSHUser,
			Auth: []ssh.AuthMethod{
				PublicKeyFile(S.SSHKeyLocation),
			},
		}
	} else {
		cfg = &ssh.ClientConfig{
			User: S.SSHUser,
			Auth: []ssh.AuthMethod{
				ssh.Password(S.SSHPassword),
			},
		}
	}

	client, e := ssh.Dial("tcp", S.SSHHost, cfg)
	return client, e

}
开发者ID:arfian,项目名称:live,代码行数:25,代码来源:ssh.go


示例13: New

// New returns a new SFTP remote Cache implementated.
func New(server, username, password, key string) (cache.Cache, error) {
	config := &ssh.ClientConfig{
		Timeout: time.Minute * 5,
		User:    username,
		Auth: []ssh.AuthMethod{
			ssh.Password(password),
		},
	}

	// private key authentication takes precedence
	if key != "" {
		signer, err := ssh.ParsePrivateKey([]byte(key))
		if err != nil {
			return nil, err
		}
		config.Auth[0] = ssh.PublicKeys(signer)
	}

	// create the ssh connection and client
	client, err := ssh.Dial("tcp", server, config)
	if err != nil {
		return nil, err
	}

	// open the sftp session using the ssh connection
	sftp, err := sftp.NewClient(client)
	if err != nil {
		client.Close()
		return nil, err
	}

	return &cacher{sftp, client}, nil
}
开发者ID:ZombieHippie,项目名称:drone-sftp-cache,代码行数:34,代码来源:sftp.go


示例14: ClientPassAuth

//ClientPassAuth provides a means of returning a ssh.Client and a Authentication function for a one time authentication procedure
func ClientPassAuth(addr string, dial, server time.Duration, cb MetaFunc) PasswordAuthCallback {

	reqs := make(chan struct{})

	return func(meta ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {

		config := &ssh.ClientConfig{}
		config.User = meta.User()
		config.Auth = []ssh.AuthMethod{
			ssh.Password(string(pass)),
		}

		cl, err := DialClient(dial, server, addr, config, reqs)

		if cb != nil {
			cb(err, meta, pass, &SSHClient{
				Client: cl,
				Meta:   meta,
				Pass:   pass,
			})
		}

		if err != nil {
			go func() {
				reqs <- struct{}{}
			}()
			return nil, err
		}

		close(reqs)
		return nil, nil
	}
}
开发者ID:influx6,项目名称:proxies,代码行数:34,代码来源:ssh.go


示例15: TestNew_Invalid

func TestNew_Invalid(t *testing.T) {
	clientConfig := &ssh.ClientConfig{
		User: "user",
		Auth: []ssh.AuthMethod{
			ssh.Password("i-am-invalid"),
		},
	}

	address := newMockLineServer(t)
	conn := func() (net.Conn, error) {
		conn, err := net.Dial("tcp", address)
		if err != nil {
			t.Errorf("Unable to accept incoming connection: %v", err)
		}
		return conn, err
	}

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

	_, err := New(address, config)
	if err == nil {
		t.Fatal("should have had an error connecting")
	}
}
开发者ID:c12simple,项目名称:packer,代码行数:27,代码来源:communicator_test.go


示例16: NewConnection

func NewConnection(host string, port int, username string, password string, key_path string) (*ssh.Client, error) {
	var config *ssh.ClientConfig
	if USEKEY {
		public_key, err := getKeyFromFile(key_path)
		if err != nil {
			log.Panic(err)
		}
		config = &ssh.ClientConfig{
			User: username,
			Auth: []ssh.AuthMethod{
				ssh.PublicKeys(public_key),
			},
		}
	} else {
		config = &ssh.ClientConfig{
			User: username,
			Auth: []ssh.AuthMethod{
				ssh.Password(password),
			},
		}
	}

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

	// Each ClientConn can support multiple interactive sessions,
	// represented by a Session.
	return client, err
}
开发者ID:newxan,项目名称:gopistrano,代码行数:31,代码来源:client.go


示例17: TestStart

func TestStart(t *testing.T) {
	clientConfig := &ssh.ClientConfig{
		User: "user",
		Auth: []ssh.AuthMethod{
			ssh.Password("pass"),
		},
	}

	address := newMockLineServer(t)
	conn := func() (net.Conn, error) {
		conn, err := net.Dial("tcp", address)
		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(address, config)
	if err != nil {
		t.Fatalf("error connecting to SSH: %s", err)
	}

	cmd := &packer.RemoteCmd{
		Command: "echo foo",
		Stdout:  new(bytes.Buffer),
	}

	client.Start(cmd)
}
开发者ID:c12simple,项目名称:packer,代码行数:34,代码来源:communicator_test.go


示例18: connect

func (d *ESX5Driver) connect() error {
	address := fmt.Sprintf("%s:%d", d.Host, d.Port)

	auth := []gossh.AuthMethod{
		gossh.Password(d.Password),
		gossh.KeyboardInteractive(
			ssh.PasswordKeyboardInteractive(d.Password)),
	}

	if d.PrivateKey != "" {
		signer, err := commonssh.FileSigner(d.PrivateKey)
		if err != nil {
			return err
		}

		auth = append(auth, gossh.PublicKeys(signer))
	}

	sshConfig := &ssh.Config{
		Connection: ssh.ConnectFunc("tcp", address),
		SSHConfig: &gossh.ClientConfig{
			User: d.Username,
			Auth: auth,
		},
	}

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

	d.comm = comm
	return nil
}
开发者ID:dantran,项目名称:packer,代码行数:34,代码来源:driver_esx5.go


示例19: main

func main() {
	flag.Parse()
	results := make(chan string, 10)
	timeout := time.After(65 * time.Second)
	config := &ssh.ClientConfig{
		User: "vagrant",
		//Auth: []ssh.AuthMethod{makeKeyring()},
		Auth: []ssh.AuthMethod{ssh.Password("vagrant")},
	}

	cmds := ParseCommands(*cmdsfile)

	for _, cmd := range cmds {
		go func(command *Cmd) {
			results <- executeCmd(command.Command, command.Host, config)
		}(cmd)
	}

	for i := 0; i < len(cmds); i++ {
		select {
		case res := <-results:
			fmt.Print(res)
		case <-timeout:
			fmt.Println("Timed out!")
			return
		}
	}
}
开发者ID:slawosz,项目名称:ssh-commander,代码行数:28,代码来源:.client.go


示例20: createSession

func (ih *InputHandler) createSession(config *InputEntry) (session *ssh.Session, err error) {

	var authMethod []ssh.AuthMethod
	var key *ssh.Signer
	if !config.Cred.IsPasswordAuth() {
		key, err = ih.parsePrivateKey(config.Cred.Identity)
		if err != nil {
			return
		}
		authMethod = []ssh.AuthMethod{ssh.PublicKeys(*key)}
	} else {
		authMethod = []ssh.AuthMethod{ssh.Password(config.Cred.Pass)}
	}

	sshConfig := new(ssh.ClientConfig)
	sshConfig.User = config.Cred.User
	sshConfig.Auth = authMethod

	port := uint16(22)
	if config.Port != 0 {
		port = config.Port
	}
	hostNameString := fmt.Sprintf("%s:%d", config.Host, port)
	client, err := ssh.Dial("tcp", hostNameString, sshConfig)
	if err != nil {
		return
	}

	session, err = client.NewSession()
	return
}
开发者ID:tri-star,项目名称:mixtail,代码行数:31,代码来源:input_handler.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ssh.PublicKeys函数代码示例发布时间:2022-05-28
下一篇:
Golang ssh.ParsePublicKey函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap