本文整理汇总了Golang中golang.org/x/crypto/ssh.ClientConfig.User方法的典型用法代码示例。如果您正苦于以下问题:Golang ClientConfig.User方法的具体用法?Golang ClientConfig.User怎么用?Golang ClientConfig.User使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/crypto/ssh.ClientConfig
的用法示例。
在下文中一共展示了ClientConfig.User方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: Connect
func (ssc *SSHConfig) Connect() (err tree_lib.TreeError) {
var (
client_conf ssh.ClientConfig
)
err.From = tree_lib.FROM_SSH_CONNECT
client_conf.User = ssc.Username
if len(ssc.Password) > 0 {
client_conf.Auth = []ssh.AuthMethod{ssh.Password(ssc.Password)}
} else {
client_conf.Auth = []ssh.AuthMethod{ssh_agent()}
}
ssc.conn, err.Err = ssh.Dial("tcp", fmt.Sprintf("%s:%d", ssc.Host, ssc.Port), &client_conf)
return
}
示例3: clientDo
func clientDo() error {
var cc ssh.ClientConfig
cc.User = string(testUser)
cc.Auth = append(cc.Auth, ssh.Password(string(testPass)))
conn, e := ssh.Dial("tcp4", "127.0.0.1:2022", &cc)
if e != nil {
return e
}
defer conn.Close()
cl, e := client.NewClient(conn)
if e != nil {
return e
}
cl.Mkdir("/D")
cl.Chmod("/D", 0700)
cl.Remove("/D")
rs, e := cl.ReadDir("/")
if e != nil {
return e
}
tdebug(rs)
return nil
}
示例4:
clientConfig = &ssh.ClientConfig{
User: "diego:" + processGuid + "/99",
Auth: []ssh.AuthMethod{ssh.Password(diegoCredentials)},
}
})
It("allows a client to complete a handshake", func() {
client, err := ssh.Dial("tcp", address, clientConfig)
Expect(err).NotTo(HaveOccurred())
client.Close()
})
})
Context("when a non-existent process guid is used", func() {
BeforeEach(func() {
clientConfig.User = "diego:bad-process-guid/999"
expectedGetActualLRPRequest = &models.ActualLRPGroupByProcessGuidAndIndexRequest{
ProcessGuid: "bad-process-guid",
Index: 999,
}
actualLRPGroupResponse = &models.ActualLRPGroupResponse{
Error: models.ErrResourceNotFound,
}
})
It("attempts to acquire the lrp info from the BBS", func() {
ssh.Dial("tcp", address, clientConfig)
Expect(fakeBBS.ReceivedRequests()).To(HaveLen(1))
})
It("fails the authentication", func() {
示例5:
ghttp.VerifyRequest("GET", "/internal/apps/app-guid/ssh_access"),
ghttp.RespondWithJSONEncoded(http.StatusUnauthorized, ""),
),
)
})
It("logs the authentication failure", func() {
_, err := ssh.Dial("tcp", address, clientConfig)
Expect(err).To(MatchError(ContainSubstring("ssh: handshake failed")))
Expect(runner).To(gbytes.Say("authentication-failed.*cf:app-guid/0"))
})
})
Context("when the app-guid does not exist in cc", func() {
BeforeEach(func() {
clientConfig.User = "cf:bad-app-guid/0"
fakeCC.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/internal/apps/bad-app-guid/ssh_access"),
ghttp.VerifyHeader(http.Header{"Authorization": []string{"bearer token"}}),
ghttp.RespondWithJSONEncoded(http.StatusNotFound, nil),
),
)
})
It("attempts to acquire the app info from cc", func() {
ssh.Dial("tcp", address, clientConfig)
Expect(fakeCC.ReceivedRequests()).To(HaveLen(1))
})