本文整理匯總了Golang中code/google/com/p/go/crypto/ssh.ClientAuthPassword函數的典型用法代碼示例。如果您正苦於以下問題:Golang ClientAuthPassword函數的具體用法?Golang ClientAuthPassword怎麽用?Golang ClientAuthPassword使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ClientAuthPassword函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sshOnConn
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
}
示例2: connect
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
}
示例3: TestNew_Invalid
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")
}
}
示例4: TestStart
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)
}
示例5: Init
func (h *RemoteHelper) Init(username, password string) {
h.config = &ssh.ClientConfig{
User: username,
Auth: []ssh.ClientAuth{
ssh.ClientAuthPassword(clientPassword(password)),
},
}
}
示例6: SSHConfigPassword
// 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)),
},
}
}
示例7: ScpHaproxyConf
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
}
示例8: main
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)
}
}
示例9: exec
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()}
}
示例10: Connect
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)
}
示例11: sshConfig
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
}
示例12: Connect
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
}
示例13: main
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())
}
示例14: Connect
// 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
}
示例15: main
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)
}