package main import ( "bufio" "golang.org/x/crypto/ssh" "os" ) func main() { SSH("user", "password", "ip_port") } func SSH(user, password, ip_port string) { PassWd := []ssh.AuthMethod{ssh.Password(password)} Conf := ssh.ClientConfig{User: user, Auth: PassWd} Client, _ := ssh.Dial("tcp", ip_port, &Conf) defer Client.Close() a := bufio.NewReader(os.Stdin) for { b, _, z := a.ReadLine() if z != nil { return } command := string(b) if session, err := Client.NewSession(); err == nil { defer session.Close() session.Stdout = os.Stdout session.Stderr = os.Stderr session.Run(command) } }
c:/Go/bin/go.exe get -v . [D:/go/src/SshTool]
package go-ssh/ssh: unrecognized import path "go-ssh/ssh" (import path does not begin with hostname)
错误: 进程退出代码 1.
#1