duanquanzhi5560 2019-03-18 16:55
浏览 76

重用来自OpenSSH客户端创建的套接字的连接

OpenSSH client has a feature called "ControlMaster" that allows to reuse connections between multiple ssh sessions over a single network connection.

I was wondering if it was possible using x/crypto/ssh package of Golang to reuse a connection from a socket that has been created by the OpenSSH client with a command like:

ssh -M -f -N -o ControlPath=$HOME/.ssh/shared.sock myUsername@targetServerName

Is there any way to create a Golang Client from this $HOME/.ssh/shared.sock socket?

We usually use the Dial function to create the Client.

func Dial(network, addr string, config *ClientConfig) (*Client, error)

But I see there is as well the NewClient function that seems to be for reusing an existing connection.

func NewClient(c Conn, chans <-chan NewChannel, reqs <-chan *Request) *Client

I struggle to understand how I can instantiate the Conn and the two channels in a proper way.

Maybe it is not doable at all?

The aim is to be able to implement a kind of wrapper of the OpenSSH client and trigger commands using Golang before/after calling the actual OpenSSH client process. It would as well avoid having to reimplement the target host/port logic and the authentication.

  • 写回答

0条回答 默认 最新

    报告相同问题?