o语言ssh简单的使用

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

    package main  
      
    import (  
        "bufio"  
        "go-ssh/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)  
            }  
        }