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

2019PHP高薪工程师学习路线图....>>>

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