<pre name="code" class="plain">package main
import (
"go-ssh/ssh"
"log"
"os"
)
func main() {
check := func(err error, msg string) {
if err != nil {
log.Fatalf("%s error: %v", msg, err)
}
}
client, err := ssh.Dial("tcp", "192.168.10.248", &ssh.ClientConfig{
User: "root",
Auth: []ssh.AuthMethod{ssh.Password("123456")},
})
check(err, "dial")
session, err := client.NewSession()
check(err, "new session")
defer session.Close()
session.Stdout = os.Stdout
session.Stderr = os.Stderr
session.Stdin = os.Stdin
modes := ssh.TerminalModes{
ssh.ECHO: 0,
ssh.TTY_OP_ISPEED: 14400,
ssh.TTY_OP_OSPEED: 14400,
}
err = session.RequestPty("xterm", 25, 100, modes)
check(err, "request pty")
err = session.Shell()
check(err, "start shell")
err = session.Wait()
check(err, "return")
}
GO语言使用开源SSH模拟终端
最新推荐文章于 2024-09-14 09:28:39 发布