GO语言使用开源SSH模拟终端的代码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

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")  
}