Connection with ssh through the shell?

I am working with Go trying to automate the tracking of all my ssh connections. I'm having trouble with the Go team. Here is my code:

cmd := exec.Command("ssh", string(c.Address)) cmd.Stderr = os.Stderr cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout err2 := cmd.Run() if err2 != nil { fmt.Print("Disconnected") } 

c.Address is equivalent to " person@192.168.1.1 " without using this ip, but when I start it, I get the following error.

 ssh: Could not resolve hostname 192.168.1.1 : nodename nor servname provided, or not known 

I can connect just fine using ssh from my terminal.

Thanks!

+5
source share
2 answers

Use the golang.org/x/crypto/ssh package.

Package Documentation

A good tutorial to get you started.

+2
source

If you

cmd := exec.Command("ssh", string(" root@192.168.1.1 "))

it works. As above if you have

cmd := exec.Command("ssh", string(" root@192.168.1.1 ")) - pay attention to the additional space

you will receive the error message that you described.

0
source

All Articles