Wrapper over the standard go library for working with ssh. The main feature is the work in one session in Shell mode (after executing a remote command, the session is not closed).

You can connect with a password and a private key.

client := gossh.NewClient()
err = client.ConnectWithPrivateKey("", "22", "viktor077", key, "12345")
if err != nil {

You can add missing encryption methods before connecting

	KeyExchanges: []string{
	Ciphers: []string{
	HostKeyAlgorithms: []string{

There are two methods for executing remote commands Exec and Run

Exec sends a command and always waits for a response.

uname, _ := client.Exec("uname -a")

Run you need to specify whether to wait for a response.

client.Send([]byte("uname -a"), false)
uname,_:=client.Send([]byte{KB_Enter}, true)

You should wait for a response only if a response should come after sending. Otherwise, the receive channel will be blocked.

client.Send([]byte("uname -a"), true) // execution will block the channel
uname,_:=client.Send([]byte{KB_Enter}, true)

Command execution is determined by searching for an input prompt using regular expressions. Two regular expressions are predefined.

`^(?:<|\[)[\w\d\_\-\.\|\/]+(?:>|])$`, //huawei switch
`^.*[\w\[email protected]]+:[\/\w\d-_~]+\s*\$\s*`,  //bash

You can change the regular expression in the same way as the encryption methods.

	InputPrompt: []string{"^[email protected]:.*\$"},


View Github