golang ssh 遠程命令終端支持
友好封裝
支持tab自動補全
遠程登錄
調用代碼:
package main
import (
"fmt"
"time"
_ "gmsec/internal/routers" // debug模式需要添加[mod]/routers 註冊註解路由
"github.com/xxjwxc/public/myssh"
)
func main() {
c, err := myssh.New("127.0.0.1", "ubuntu", "123456", 22)
if err != nil {
fmt.Println("err", err)
}
output, err := c.Run("free -h")
fmt.Printf("%v\n%v", output, err) // 返回字符串
time.Sleep(1 * time.Second)
// c.RunTerminal("top") 交互式
// time.Sleep(1 * time.Second)
c.Terminal() // 進入
}