<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") }
时间: 2024-10-28 14:23:21