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

Golang ssh.PublicKeysCallback函数代码示例

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

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



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

示例1: DialSSH

func DialSSH(addr string, username string, keyFilename string) (conn *SSHConn, err error) {
	conn = &SSHConn{}

	if keyFilename != "" {
		pemKey, err := ioutil.ReadFile(keyFilename)
		if err != nil {
			return
		}

		signer, err := ssh.ParsePrivateKey(pemKey)
		if err != nil {
			return
		}

		conn.Auth = ssh.PublicKeys(signer)
	} else {
		sshAgent, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
		if err != nil {
			return
		}

		conn.Auth = ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers)
	}

	conn.Config = &ssh.ClientConfig{
		User: username,
		Auth: []ssh.AuthMethod{
			conn.Auth,
		},
	}

	conn.Client, err = ssh.Dial("tcp", fmt.Sprintf("%s:22", addr), conn.Config)
	return
}
开发者ID:rgeorgiev583,项目名称:gonfs,代码行数:34,代码来源:dial.go


示例2: ExampleClientAgent

func ExampleClientAgent() {
	// ssh-agent has a UNIX socket under $SSH_AUTH_SOCK
	socket := os.Getenv("SSH_AUTH_SOCK")
	conn, err := net.Dial("unix", socket)
	if err != nil {
		log.Fatalf("net.Dial: %v", err)
	}
	agentClient := agent.NewClient(conn)
	config := &ssh.ClientConfig{
		User: "username",
		Auth: []ssh.AuthMethod{
			// Use a callback rather than PublicKeys
			// so we only consult the agent once the remote server
			// wants it.
			ssh.PublicKeysCallback(agentClient.Signers),
		},
	}

	sshc, err := ssh.Dial("tcp", "localhost:22", config)
	if err != nil {
		log.Fatalf("Dial: %v", err)
	}
	// .. use sshc
	sshc.Close()
}
开发者ID:Rudloff,项目名称:platform,代码行数:25,代码来源:example_test.go


示例3: SSHAgent

func SSHAgent() ssh.AuthMethod {
	if sshAgent, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); err == nil {
		return ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers)
	}

	return nil
}
开发者ID:ebenoist,项目名称:ply,代码行数:7,代码来源:ssh.go


示例4: Connection

func Connection(info ConnetctionInfo) *ssh.Client {
	var auths []ssh.AuthMethod
	auths = append(auths, privateKey...)
	if aconn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); err == nil {
		auths = append(auths, ssh.PublicKeysCallback(agent.NewClient(aconn).Signers))
	}
	auths = append(auths, ssh.Password(info.Passwd))
	config := ssh.ClientConfig{
		User: info.User,
		Auth: auths,
	}
	for i := 0; i < 3; i++ {
		//conn, err := ssh.Dial("tcp", fmt.Sprintf("%s:%s", info.IP, info.Port), &config)
		conn, err := ssh.DialTimeOut("tcp", fmt.Sprintf("%s:%s", info.IP, info.Port), 30, &config)
		if err == nil {
			return conn
		}
		if i == 2 && err != nil {
			ErrorList = append(ErrorList, fmt.Sprintf("连接%s失败:%s\n", info.IP, err))
			return nil
		}
		time.Sleep(1e9)
	}
	return nil
}
开发者ID:czxichen,项目名称:Goprograme,代码行数:25,代码来源:connectin.go


示例5: Connect

func (sfs *SftpFileSystem) Connect() error {
	var auths []ssh.AuthMethod
	if aconn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); err == nil {
		auths = append(auths, ssh.PublicKeysCallback(agent.NewClient(aconn).Signers))
	}
	if len(sfs.sp.Password) != 0 {
		auths = append(auths, ssh.Password(sfs.sp.Password))
	}

	config := ssh.ClientConfig{
		User: sfs.sp.Username,
		Auth: auths,
	}
	var err error
	sfs.sshClient, err = ssh.Dial("tcp", sfs.sp.Server, &config)
	if err != nil {
		log.Println("unable to connect to [%s]: %v", sfs.sp.Server, err)
		return err
	}

	sfs.sftpClient, err = sftp.NewClient(sfs.sshClient)
	if err != nil {
		log.Println("unable to start sftp subsytem: %v", err)
		return err
	}
	return nil
}
开发者ID:peernode,项目名称:Taipei-Torrent,代码行数:27,代码来源:sftp.go


示例6: connect

func (this *SSHExecutor) connect() error {
	// auths holds the detected ssh auth methods
	auths := []ssh.AuthMethod{}

	// figure out what auths are requested, what is supported
	if this.Password != "" {
		auths = append(auths, ssh.Password(this.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()
	}

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

	client, err := ssh.Dial("tcp", this.Hostname+":"+strconv.Itoa(this.Port), config)
	if err != nil {
		return err
	}

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

	this.Session = session

	return nil
}
开发者ID:vence722,项目名称:ssh_tool,代码行数:33,代码来源:executor.go


示例7: main

func main() {
	auth_socket := os.Getenv("SSH_AUTH_SOCK")
	if auth_socket == "" {
		log.Fatal(errors.New("no $SSH_AUTH_SOCK defined"))
	}
	conn, err := net.Dial("unix", auth_socket)
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()
	ag := agent.NewClient(conn)
	auths := []ssh.AuthMethod{ssh.PublicKeysCallback(ag.Signers)}

	config := &ssh.ClientConfig{
		User:            Username,
		Auth:            auths,
		HostKeyCallback: KeyScanCallback,
	}

	var wg sync.WaitGroup
	go out(&wg)
	reader := bufio.NewReader(os.Stdin)
	for {
		server, err := reader.ReadString('\n')
		if err == io.EOF {
			break
		}
		server = server[:len(server)-1] // chomp
		wg.Add(2)                       // dial and print
		go dial(server, config, &wg)
	}
	wg.Wait()
}
开发者ID:szuecs,项目名称:go-ssh-keyscan,代码行数:33,代码来源:go-ssh-keyscan.go


示例8: Client

func (conf *SshConfig) Client() (*ssh.Client, error) {

	auths := []ssh.AuthMethod{}

	if !Empty(conf.Password) {
		auths = append(auths, ssh.Password(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(conf.Key); err == nil {
		auths = append(auths, ssh.PublicKeys(pubkey))
	}

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

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

	return client, nil
}
开发者ID:kbdhero,项目名称:cogs,代码行数:29,代码来源:base.go


示例9: 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


示例10: sshClient

func sshClient(username, host string) (*ssh.Client, error) {
	agentconn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
	if err != nil {
		return nil, err
	}

	aclient := agent.NewClient(agentconn)

	conf := &ssh.ClientConfig{
		User: username,
		Auth: []ssh.AuthMethod{
			ssh.PublicKeysCallback(aclient.Signers),
		},
	}

	if strings.Index(host, ":") < 0 {
		host = host + ":22"
	}

	cli, err := ssh.Dial("tcp", host, conf)
	if err != nil {
		return nil, err
	}

	return cli, nil
}
开发者ID:cmikk,项目名称:sshttp,代码行数:26,代码来源:ssh.go


示例11: reconnect

func (ctx *ExecContext) reconnect() (err error) {
	if ctx.hostname != "" {
		ctx.isReconnecting = true
		username := ctx.username
		addr := fmt.Sprintf("%s:%d", ctx.hostname, ctx.port)
		ctx.unlock()
		agentConn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
		if err != nil {
			ctx.lock()
			ctx.isReconnecting = false
			return err
		}
		defer agentConn.Close()
		ag := agent.NewClient(agentConn)
		auths := []ssh.AuthMethod{ssh.PublicKeysCallback(ag.Signers)}
		config := &ssh.ClientConfig{
			User: username,
			Auth: auths,
		}
		conn, err := net.DialTimeout("tcp", addr, networkTimeout)
		if err != nil {
			ctx.lock()
			ctx.isReconnecting = false
			return err
		}

		timeoutConn := &Conn{conn, networkTimeout, networkTimeout}
		c, chans, reqs, err := ssh.NewClientConn(timeoutConn, addr, config)
		if err != nil {
			ctx.lock()
			ctx.isReconnecting = false
			return err
		}
		client := ssh.NewClient(c, chans, reqs)

		// Send periodic keepalive messages
		go func() {
			t := time.NewTicker(networkTimeout / 2)
			defer t.Stop()
			for {
				<-t.C
				_, _, err := client.Conn.SendRequest("[email protected]", true, nil)
				if err != nil {
					ctx.lock()
					if ctx.sshClient == client {
						ctx.isConnected = false
					}
					ctx.unlock()
					return
				}
			}
		}()
		ctx.lock()
		ctx.isReconnecting = false
		ctx.sshClient = client
	}
	ctx.isConnected = true
	return nil
}
开发者ID:tillberg,项目名称:bismuth,代码行数:59,代码来源:bismuth.go


示例12: sshAgent

func sshAgent() (ssh.AuthMethod, func(), error) {
	sshAgent, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
	if err != nil {
		return nil, func() {}, err
	}
	method := ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers)
	return method, func() { _ = sshAgent.Close() }, nil
}
开发者ID:aybabtme,项目名称:multisshtail,代码行数:8,代码来源:main.go


示例13: loadEnvAgent

func loadEnvAgent() (auths []ssh.AuthMethod, err error) {
	sshAuthSock, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
	if err != nil {
		return
	}
	defer sshAuthSock.Close()
	ag := agent.NewClient(sshAuthSock)
	auths = []ssh.AuthMethod{ssh.PublicKeysCallback(ag.Signers)}
	return
}
开发者ID:colebrumley,项目名称:mssh-go,代码行数:10,代码来源:keys.go


示例14: getAgentAuth

func getAgentAuth() (auth ssh.AuthMethod, ok bool) {
	if sock := os.Getenv("SSH_AUTH_SOCK"); len(sock) > 0 {
		if agconn, err := net.Dial("unix", sock); err == nil {
			ag := agent.NewClient(agconn)
			auth = ssh.PublicKeysCallback(ag.Signers)
			ok = true
		}
	}
	return
}
开发者ID:rapidloop,项目名称:rtop-bot,代码行数:10,代码来源:sshhelper.go


示例15: setupSshClient

func setupSshClient() (*ssh.Client, net.Conn, error) {
	agentConn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
	if err != nil {
		return nil, nil, err
	}
	agentClient := agent.NewClient(agentConn)
	client, err := ssh.Dial("tcp", Config.Host, &ssh.ClientConfig{
		User: Config.Username,
		Auth: []ssh.AuthMethod{ssh.PublicKeysCallback(agentClient.Signers)},
	})
	return client, agentConn, err
}
开发者ID:kristoiv,项目名称:nfssh,代码行数:12,代码来源:ssh.go


示例16: UseAgent

func (r *SSHCmd) UseAgent() error {
	if r.connected {
		return fmt.Errorf("Cannot add authentication methods while being connected")
	}
	sshAgent, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
	if err != nil {
		return err
	}
	r.config.Auth = append(r.config.Auth, ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers))

	return nil
}
开发者ID:geisbruch,项目名称:cmt,代码行数:12,代码来源:ssh.go


示例17: SSHConfigPubKeyAgent

// SSHConfigPubKeyAgent is a convience function that takes a username and
// returns a new ssh.Clientconfig setup to pass credentials received from
// an ssh agent
func SSHConfigPubKeyAgent(user string) (*ssh.ClientConfig, error) {
	c, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
	if err != nil {
		return nil, err
	}
	return &ssh.ClientConfig{
		User: user,
		Auth: []ssh.AuthMethod{
			ssh.PublicKeysCallback(agent.NewClient(c).Signers),
		},
	}, nil
}
开发者ID:Juniper,项目名称:go-netconf,代码行数:15,代码来源:transport_ssh.go


示例18: Connect

// connects to remote server using MakeConfig struct and returns *ssh.Session
func (ssh_conf *MakeConfig) Connect() (*ssh.Session, error) {

	auths := []ssh.AuthMethod{}

	// Parse ssh config
	hosts, err := config.ParseSSHConfig(os.Getenv("HOME") + "/.ssh/config")
	if err == nil {
		for _, host := range hosts {
			if stringInSlice(ssh_conf.Server, host.Host) {
				ssh_conf.Server = host.HostName
				ssh_conf.User = host.User
				ssh_conf.Port = strconv.Itoa(host.Port)
				ssh_conf.Key = []string{host.IdentityFile}
			}
		}
	}

	var keys []ssh.Signer

	for _, v := range ssh_conf.Key {
		pubkey, err := getKeyFile(v)
		if err != nil {
			continue
		}
		keys = append(keys, pubkey)
	}

	// in POSIX systems, try ssh auth sock
	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()
	}

	auths = append(auths, ssh.PublicKeys(keys...))

	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:chonthu,项目名称:ssh,代码行数:53,代码来源:ssh.go


示例19: main

func main() {
	var auths []ssh.AuthMethod
	if aconn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); err == nil {
		auths = append(auths, ssh.PublicKeysCallback(agent.NewClient(aconn).Signers))

	}
	if *PASS != "" {
		auths = append(auths, ssh.Password(*PASS))
	}

	config := ssh.ClientConfig{
		User: *USER,
		Auth: auths,
	}
	addr := fmt.Sprintf("%s:%d", *HOST, *PORT)
	conn, err := ssh.Dial("tcp", addr, &config)
	if err != nil {
		log.Fatalf("unable to connect to [%s]: %v", addr, err)
	}
	defer conn.Close()

	c, err := sftp.NewClient(conn)
	if err != nil {
		log.Fatalf("unable to start sftp subsytem: %v", err)
	}
	defer c.Close()

	w, err := c.OpenFile("/dev/null", syscall.O_WRONLY)
	if err != nil {
		log.Fatal(err)
	}
	defer w.Close()

	f, err := os.Open("/dev/zero")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	const size int64 = 1e9

	log.Printf("writing %v bytes", size)
	t1 := time.Now()
	n, err := io.Copy(w, io.LimitReader(f, size))
	if err != nil {
		log.Fatal(err)
	}
	if n != size {
		log.Fatalf("copy: expected %v bytes, got %d", size, n)
	}
	log.Printf("wrote %v bytes in %s", size, time.Since(t1))
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:52,代码来源:main.go


示例20: connectToAgent

func (c *comm) connectToAgent() {
	if c.client == nil {
		return
	}

	if c.config.DisableAgent {
		log.Printf("[INFO] SSH agent forwarding is disabled.")
		return
	}

	// open connection to the local agent
	socketLocation := os.Getenv("SSH_AUTH_SOCK")
	if socketLocation == "" {
		log.Printf("[INFO] no local agent socket, will not connect agent")
		return
	}
	agentConn, err := net.Dial("unix", socketLocation)
	if err != nil {
		log.Printf("[ERROR] could not connect to local agent socket: %s", socketLocation)
		return
	}

	// create agent and add in auth
	forwardingAgent := agent.NewClient(agentConn)
	if forwardingAgent == nil {
		log.Printf("[ERROR] Could not create agent client")
		agentConn.Close()
		return
	}

	// add callback for forwarding agent to SSH config
	// XXX - might want to handle reconnects appending multiple callbacks
	auth := ssh.PublicKeysCallback(forwardingAgent.Signers)
	c.config.SSHConfig.Auth = append(c.config.SSHConfig.Auth, auth)
	agent.ForwardToAgent(c.client, forwardingAgent)

	// Setup a session to request agent forwarding
	session, err := c.newSession()
	if err != nil {
		return
	}
	defer session.Close()

	err = agent.RequestAgentForwarding(session)
	if err != nil {
		log.Printf("[ERROR] RequestAgentForwarding: %#v", err)
		return
	}

	log.Printf("[INFO] agent forwarding enabled")
	return
}
开发者ID:threatstream,项目名称:packer,代码行数:52,代码来源:communicator.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang ssh.Unmarshal函数代码示例发布时间:2022-05-28
下一篇:
Golang ssh.PublicKeys函数代码示例发布时间: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