Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (

"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
"golang.org/x/crypto/ssh/terminal"
)

// Client is a wrapper over the SSH connection/sessions.
type SSHClient struct {
conn *ssh.Client
sess *ssh.Session
ask bool
user string
host string
remoteStdin io.WriteCloser
Expand Down Expand Up @@ -51,6 +53,11 @@ func (c *SSHClient) parseHost(host string) error {

if at := strings.Index(c.host, "@"); at != -1 {
c.user = c.host[:at]
c.ask = false
if ask := strings.Index(c.user, "ask:"); ask == 0 {
c.user = c.user[4:]
c.ask = true
}
c.host = c.host[at+1:]
}

Expand Down Expand Up @@ -133,11 +140,24 @@ func (c *SSHClient) ConnectWith(host string, dialer SSHDialFunc) error {
return err
}

config := &ssh.ClientConfig{
User: c.user,
Auth: []ssh.AuthMethod{
authMethod,
},
var config *ssh.ClientConfig
if c.ask {
fmt.Print("Enter Password for " + c.user + "@" + c.host + ": ")
pass, _ := terminal.ReadPassword(0)
fmt.Println("")
config = &ssh.ClientConfig{
User: c.user,
Auth: []ssh.AuthMethod{
ssh.Password(string(pass)),
},
}
} else {
config = &ssh.ClientConfig{
User: c.user,
Auth: []ssh.AuthMethod{
authMethod,
},
}
}

c.conn, err = dialer("tcp", c.host, config)
Expand Down