dongnaizao8039 2019-08-04 11:33
浏览 123

利用现有SSH连接连接到远程主机

I was previously using asyncssh for python. It has a feature that you can provide an already available connection to connect to a new host. I am looking into the ssh documentation. I don't see any option that can do this trick, not sure if I have to do some tunneling manually.

What I want is to connect to a machine using SSH that has auth, then use that connection to connect to another machine that has different auth then the first machine.

ncmConfig := &ssh.ClientConfig{
    User:            "xyz",
    HostKeyCallback: ssh.InsecureIgnoreHostKey(),
    Auth: []ssh.AuthMethod{
        ssh.Password("xyz!"),
    },
}

routerConfig := &ssh.ClientConfig{
    User:            "xyz1",
    HostKeyCallback: ssh.InsecureIgnoreHostKey(),
    Auth: []ssh.AuthMethod{
        ssh.Password("xyz2"),
    },
}
ncm := "1.1.1.1"
router := "2.2.2.2
conn, err := ssh.Dial("tcp", ncm+":22", ncmConfig)
if err != nil {
    log.Println(err)
}

# how can I use the conn to connect to a new machine.
  • 写回答

1条回答 默认 最新

  • duanlu1908 2019-08-05 08:07
    关注
    conn2, err := conn.Dial("tcp", router+":22")
    if err != nil {
        log.Println(err)
    }
    
    conn3, chans, reqs, err := ssh.NewClientConn(conn2, router+":22", routerConfig)
    if err != nil {
        log.Println(err)
    }
    
    conn4 := ssh.NewClient(conn3, chans, reqs)
    

    conn4 is the new connection.

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算