Пример #1
0
func (c *Client) Connect() (e error) {
	if c.Port == 0 {
		c.Port = 22
	}

	var auths []ssh.AuthMethod
	if c.password != "" {
		auths = append(auths, ssh.Password(c.password))
	} else if c.Agent, e = net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); e == nil {
		auths = append(auths, ssh.PublicKeysCallback(agent.NewClient(c.Agent).Signers))
	}

	config := &ssh.ClientConfig{
		User: c.User,
		Auth: auths,
	}
	c.Conn, e = ssh.Dial("tcp", fmt.Sprintf("%s:%d", c.Host, c.Port), config)
	return e
}
Пример #2
0
func (c *Config) Connection() (*ssh.Client, error) {
	port := c.Port
	if port == 0 {
		port = 22
	}

	var auths []ssh.AuthMethod
	if c.Password != "" {
		auths = append(auths, ssh.Password(c.Password))
	} else if sshAgent, e := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); e == nil {
		auths = append(auths, ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers))
	}

	config := &ssh.ClientConfig{
		User: c.User,
		Auth: auths,
	}
	return ssh.Dial("tcp", fmt.Sprintf("%s:%d", c.Host, port), config)
}