Discussion:
session.Run results in ssh.channelEOFMsg
(too old to reply)
Jonathan Pittman
2011-12-12 21:00:46 UTC
Permalink
Following the example client code for exp/ssh, I am getting this message
after doing a session.Run("echo hi").

code...

session1, err := client.NewSession()
if err != nil {
log.Fatal("Error creating session1: ", err)
}
log.Println("Session1 created.")

if err := session1.Run(*cmdString); err != nil {
log.Fatal("Failed to Run: " + err.Error())
}
reader := bufio.NewReader(session1.Stdin)
line, _, _ := reader.ReadLine()
fmt.Println(line)
session1.Close()

cmdString in this case comes from flag.String(). This is the error message:

Failed to Run: wait: unexpected packet *ssh.channelEOFMsg received: &{0}

On the server side, it appears to accept authentication and shows the exec
of the command. I also ran this using a typical openssh client as well.

Using Go client...

sshd[13020]: Set /proc/self/oom_adj to 0
sshd[13020]: Connection from 192.168.1.101 port 45531
sshd[13020]: Postponed publickey for root from 192.168.1.101 port 45531
ssh2 [preauth]
sshd[13020]: Accepted publickey for root from 192.168.1.101 port 45531 ssh2
sshd[13020]: Found matching RSA key ...
sshd[13020]: Exec command 'echo hi'
sshd[13020]: Connection closed by 192.168.1.101
sshd[13020]: Transferred: sent 2600, received 2512 bytes
sshd[13020]: Closing connection to 192.168.1.101 port 45531

Using OpenSSH client...

sshd[12825]: Set /proc/self/oom_adj to 0
sshd[12825]: Connection from 192.168.1.101 port 36182
sshd[12825]: Postponed publickey for root from 192.168.1.101 port 36182
ssh2 [preauth]
sshd[12825]: Accepted publickey for root from 192.168.1.101 port 36182 ssh2
sshd[12825]: Found matching RSA key ...
sshd[12825]: Exec command 'echo hi'
sshd[12825]: Received disconnect from 192.168.1.101: 11: disconnected by
user

Anyone else run into this or have an idea as to what is happening here?
(fwiw, I have tried commands other than "echo hi")
Dave Cheney
2011-12-12 21:07:58 UTC
Permalink
Hi Jonathan,

Which release/revision is this?

Cheers

Dave

Sent from my iPhone
Following the example client code for exp/ssh, I am getting this message after doing a session.Run("echo hi").
code...
session1, err := client.NewSession()
if err != nil {
log.Fatal("Error creating session1: ", err)
}
log.Println("Session1 created.")
if err := session1.Run(*cmdString); err != nil {
log.Fatal("Failed to Run: " + err.Error())
}
reader := bufio.NewReader(session1.Stdin)
line, _, _ := reader.ReadLine()
fmt.Println(line)
session1.Close()
Failed to Run: wait: unexpected packet *ssh.channelEOFMsg received: &{0}
On the server side, it appears to accept authentication and shows the exec of the command. I also ran this using a typical openssh client as well.
Using Go client...
sshd[13020]: Set /proc/self/oom_adj to 0
sshd[13020]: Connection from 192.168.1.101 port 45531
sshd[13020]: Postponed publickey for root from 192.168.1.101 port 45531 ssh2 [preauth]
sshd[13020]: Accepted publickey for root from 192.168.1.101 port 45531 ssh2
sshd[13020]: Found matching RSA key ...
sshd[13020]: Exec command 'echo hi'
sshd[13020]: Connection closed by 192.168.1.101
sshd[13020]: Transferred: sent 2600, received 2512 bytes
sshd[13020]: Closing connection to 192.168.1.101 port 45531
Using OpenSSH client...
sshd[12825]: Set /proc/self/oom_adj to 0
sshd[12825]: Connection from 192.168.1.101 port 36182
sshd[12825]: Postponed publickey for root from 192.168.1.101 port 36182 ssh2 [preauth]
sshd[12825]: Accepted publickey for root from 192.168.1.101 port 36182 ssh2
sshd[12825]: Found matching RSA key ...
sshd[12825]: Exec command 'echo hi'
sshd[12825]: Received disconnect from 192.168.1.101: 11: disconnected by user
Anyone else run into this or have an idea as to what is happening here? (fwiw, I have tried commands other than "echo hi")
Jonathan Pittman
2011-12-12 21:14:15 UTC
Permalink
6g version weekly.2011-12-06 10712

It was doing it with the previous release (weekly.2011-12-02) as well. I
am not sure if it was doing it further back than that. I just got to this
point recently after learning to dance with the ssh-agent. FWIW, for these
tests, I am still using a private key on disk.
Post by Dave Cheney
Hi Jonathan,
Which release/revision is this?
Cheers
Dave
Sent from my iPhone
Following the example client code for exp/ssh, I am getting this message
after doing a session.Run("echo hi").
code...
session1, err := client.NewSession()
if err != nil {
log.Fatal("Error creating session1: ", err)
}
log.Println("Session1 created.")
if err := session1.Run(*cmdString); err != nil {
log.Fatal("Failed to Run: " + err.Error())
}
reader := bufio.NewReader(session1.Stdin)
line, _, _ := reader.ReadLine()
fmt.Println(line)
session1.Close()
Failed to Run: wait: unexpected packet *ssh.channelEOFMsg received: &{0}
On the server side, it appears to accept authentication and shows the exec
of the command. I also ran this using a typical openssh client as well.
Using Go client...
sshd[13020]: Set /proc/self/oom_adj to 0
sshd[13020]: Connection from 192.168.1.101 port 45531
sshd[13020]: Postponed publickey for root from 192.168.1.101 port 45531 ssh2 [preauth]
sshd[13020]: Accepted publickey for root from 192.168.1.101 port 45531 ssh2
sshd[13020]: Found matching RSA key ...
sshd[13020]: Exec command 'echo hi'
sshd[13020]: Connection closed by 192.168.1.101
sshd[13020]: Transferred: sent 2600, received 2512 bytes
sshd[13020]: Closing connection to 192.168.1.101 port 45531
Using OpenSSH client...
sshd[12825]: Set /proc/self/oom_adj to 0
sshd[12825]: Connection from 192.168.1.101 port 36182
sshd[12825]: Postponed publickey for root from 192.168.1.101 port 36182 ssh2 [preauth]
sshd[12825]: Accepted publickey for root from 192.168.1.101 port 36182 ssh2
sshd[12825]: Found matching RSA key ...
sshd[12825]: Exec command 'echo hi'
sshd[12825]: Received disconnect from 192.168.1.101: 11: disconnected by user
Anyone else run into this or have an idea as to what is happening here?
(fwiw, I have tried commands other than "echo hi")
Dave Cheney
2011-12-12 21:20:53 UTC
Permalink
Thanks, you're able to call NewSession so this is not an authentication problem.

Sent from my iPhone
Post by Jonathan Pittman
6g version weekly.2011-12-06 10712
It was doing it with the previous release (weekly.2011-12-02) as well. I am not sure if it was doing it further back than that. I just got to this point recently after learning to dance with the ssh-agent. FWIW, for these tests, I am still using a private key on disk.
Hi Jonathan,
Which release/revision is this?
Cheers
Dave
Sent from my iPhone
Following the example client code for exp/ssh, I am getting this message after doing a session.Run("echo hi").
code...
session1, err := client.NewSession()
if err != nil {
log.Fatal("Error creating session1: ", err)
}
log.Println("Session1 created.")
if err := session1.Run(*cmdString); err != nil {
log.Fatal("Failed to Run: " + err.Error())
}
reader := bufio.NewReader(session1.Stdin)
line, _, _ := reader.ReadLine()
fmt.Println(line)
session1.Close()
Failed to Run: wait: unexpected packet *ssh.channelEOFMsg received: &{0}
On the server side, it appears to accept authentication and shows the exec of the command. I also ran this using a typical openssh client as well.
Using Go client...
sshd[13020]: Set /proc/self/oom_adj to 0
sshd[13020]: Connection from 192.168.1.101 port 45531
sshd[13020]: Postponed publickey for root from 192.168.1.101 port 45531 ssh2 [preauth]
sshd[13020]: Accepted publickey for root from 192.168.1.101 port 45531 ssh2
sshd[13020]: Found matching RSA key ...
sshd[13020]: Exec command 'echo hi'
sshd[13020]: Connection closed by 192.168.1.101
sshd[13020]: Transferred: sent 2600, received 2512 bytes
sshd[13020]: Closing connection to 192.168.1.101 port 45531
Using OpenSSH client...
sshd[12825]: Set /proc/self/oom_adj to 0
sshd[12825]: Connection from 192.168.1.101 port 36182
sshd[12825]: Postponed publickey for root from 192.168.1.101 port 36182 ssh2 [preauth]
sshd[12825]: Accepted publickey for root from 192.168.1.101 port 36182 ssh2
sshd[12825]: Found matching RSA key ...
sshd[12825]: Exec command 'echo hi'
sshd[12825]: Received disconnect from 192.168.1.101: 11: disconnected by user
Anyone else run into this or have an idea as to what is happening here? (fwiw, I have tried commands other than "echo hi")
Jonathan Pittman
2011-12-12 21:57:02 UTC
Permalink
Indeed... I am able to get the output this way.

session, err := client.NewSession()
if err != nil {
log.Fatal("Error creating session: ", err)
}
log.Println("Session created.")

myBuf := new(bytes.Buffer)
session.Stdout = myBuf

if err := session.Run(*cmdString); err != nil {
log.Println("Failed to Run: " + err.Error())
}

fmt.Println(myBuf.String())
session.Close()

As for the "unexpected packet" error, is that a bug or something that
should be handled differently? Does the fact that the error is an EOF
simply mean it should be handled differently by me or by the code at
http://weekly.golang.org/src/pkg/exp/ssh/session.go?h=unexpected+packet#L277?
Post by Dave Cheney
Thanks, you're able to call NewSession so this is not an authentication problem.
Sent from my iPhone
6g version weekly.2011-12-06 10712
It was doing it with the previous release (weekly.2011-12-02) as well. I
am not sure if it was doing it further back than that. I just got to this
point recently after learning to dance with the ssh-agent. FWIW, for these
tests, I am still using a private key on disk.
Post by Dave Cheney
Hi Jonathan,
Which release/revision is this?
Cheers
Dave
Sent from my iPhone
Following the example client code for exp/ssh, I am getting this message
after doing a session.Run("echo hi").
code...
session1, err := client.NewSession()
if err != nil {
log.Fatal("Error creating session1: ", err)
}
log.Println("Session1 created.")
if err := session1.Run(*cmdString); err != nil {
log.Fatal("Failed to Run: " + err.Error())
}
reader := bufio.NewReader(session1.Stdin)
line, _, _ := reader.ReadLine()
fmt.Println(line)
session1.Close()
Failed to Run: wait: unexpected packet *ssh.channelEOFMsg received: &{0}
On the server side, it appears to accept authentication and shows the
exec of the command. I also ran this using a typical openssh client as
well.
Using Go client...
sshd[13020]: Set /proc/self/oom_adj to 0
sshd[13020]: Connection from 192.168.1.101 port 45531
sshd[13020]: Postponed publickey for root from 192.168.1.101 port 45531 ssh2 [preauth]
sshd[13020]: Accepted publickey for root from 192.168.1.101 port 45531 ssh2
sshd[13020]: Found matching RSA key ...
sshd[13020]: Exec command 'echo hi'
sshd[13020]: Connection closed by 192.168.1.101
sshd[13020]: Transferred: sent 2600, received 2512 bytes
sshd[13020]: Closing connection to 192.168.1.101 port 45531
Using OpenSSH client...
sshd[12825]: Set /proc/self/oom_adj to 0
sshd[12825]: Connection from 192.168.1.101 port 36182
sshd[12825]: Postponed publickey for root from 192.168.1.101 port 36182 ssh2 [preauth]
sshd[12825]: Accepted publickey for root from 192.168.1.101 port 36182 ssh2
sshd[12825]: Found matching RSA key ...
sshd[12825]: Exec command 'echo hi'
sshd[12825]: Received disconnect from 192.168.1.101: 11: disconnected by user
Anyone else run into this or have an idea as to what is happening here?
(fwiw, I have tried commands other than "echo hi")
Dave Cheney
2011-12-13 07:00:45 UTC
Permalink
My guess is it shouldn't happen at all. Please let me look into it further this evening.

Sent from my iPhone
Post by Jonathan Pittman
Indeed... I am able to get the output this way.
session, err := client.NewSession()
if err != nil {
log.Fatal("Error creating session: ", err)
}
log.Println("Session created.")
myBuf := new(bytes.Buffer)
session.Stdout = myBuf
if err := session.Run(*cmdString); err != nil {
log.Println("Failed to Run: " + err.Error())
}
fmt.Println(myBuf.String())
session.Close()
As for the "unexpected packet" error, is that a bug or something that should be handled differently? Does the fact that the error is an EOF simply mean it should be handled differently by me or by the code at http://weekly.golang.org/src/pkg/exp/ssh/session.go?h=unexpected+packet#L277 ?
Thanks, you're able to call NewSession so this is not an authentication problem.
Sent from my iPhone
Post by Jonathan Pittman
6g version weekly.2011-12-06 10712
It was doing it with the previous release (weekly.2011-12-02) as well. I am not sure if it was doing it further back than that. I just got to this point recently after learning to dance with the ssh-agent. FWIW, for these tests, I am still using a private key on disk.
Hi Jonathan,
Which release/revision is this?
Cheers
Dave
Sent from my iPhone
Following the example client code for exp/ssh, I am getting this message after doing a session.Run("echo hi").
code...
session1, err := client.NewSession()
if err != nil {
log.Fatal("Error creating session1: ", err)
}
log.Println("Session1 created.")
if err := session1.Run(*cmdString); err != nil {
log.Fatal("Failed to Run: " + err.Error())
}
reader := bufio.NewReader(session1.Stdin)
line, _, _ := reader.ReadLine()
fmt.Println(line)
session1.Close()
Failed to Run: wait: unexpected packet *ssh.channelEOFMsg received: &{0}
On the server side, it appears to accept authentication and shows the exec of the command. I also ran this using a typical openssh client as well.
Using Go client...
sshd[13020]: Set /proc/self/oom_adj to 0
sshd[13020]: Connection from 192.168.1.101 port 45531
sshd[13020]: Postponed publickey for root from 192.168.1.101 port 45531 ssh2 [preauth]
sshd[13020]: Accepted publickey for root from 192.168.1.101 port 45531 ssh2
sshd[13020]: Found matching RSA key ...
sshd[13020]: Exec command 'echo hi'
sshd[13020]: Connection closed by 192.168.1.101
sshd[13020]: Transferred: sent 2600, received 2512 bytes
sshd[13020]: Closing connection to 192.168.1.101 port 45531
Using OpenSSH client...
sshd[12825]: Set /proc/self/oom_adj to 0
sshd[12825]: Connection from 192.168.1.101 port 36182
sshd[12825]: Postponed publickey for root from 192.168.1.101 port 36182 ssh2 [preauth]
sshd[12825]: Accepted publickey for root from 192.168.1.101 port 36182 ssh2
sshd[12825]: Found matching RSA key ...
sshd[12825]: Exec command 'echo hi'
sshd[12825]: Received disconnect from 192.168.1.101: 11: disconnected by user
Anyone else run into this or have an idea as to what is happening here? (fwiw, I have tried commands other than "echo hi")
Jonathan Pittman
2011-12-13 16:34:26 UTC
Permalink
Thanks for you help on this!
Post by Dave Cheney
My guess is it shouldn't happen at all. Please let me look into it further this evening.
Sent from my iPhone
Indeed... I am able to get the output this way.
session, err := client.NewSession()
if err != nil {
log.Fatal("Error creating session: ", err)
}
log.Println("Session created.")
myBuf := new(bytes.Buffer)
session.Stdout = myBuf
if err := session.Run(*cmdString); err != nil {
log.Println("Failed to Run: " + err.Error())
}
fmt.Println(myBuf.String())
session.Close()
As for the "unexpected packet" error, is that a bug or something that
should be handled differently? Does the fact that the error is an EOF
simply mean it should be handled differently by me or by the code at
http://weekly.golang.org/src/pkg/exp/ssh/session.go?h=unexpected+packet#L277?
Post by Dave Cheney
Thanks, you're able to call NewSession so this is not an authentication problem.
Sent from my iPhone
6g version weekly.2011-12-06 10712
It was doing it with the previous release (weekly.2011-12-02) as well. I
am not sure if it was doing it further back than that. I just got to this
point recently after learning to dance with the ssh-agent. FWIW, for these
tests, I am still using a private key on disk.
Post by Dave Cheney
Hi Jonathan,
Which release/revision is this?
Cheers
Dave
Sent from my iPhone
On 13/12/2011, at 8:00, Jonathan Pittman <
Following the example client code for exp/ssh, I am getting this message
after doing a session.Run("echo hi").
code...
session1, err := client.NewSession()
if err != nil {
log.Fatal("Error creating session1: ", err)
}
log.Println("Session1 created.")
if err := session1.Run(*cmdString); err != nil {
log.Fatal("Failed to Run: " + err.Error())
}
reader := bufio.NewReader(session1.Stdin)
line, _, _ := reader.ReadLine()
fmt.Println(line)
session1.Close()
Failed to Run: wait: unexpected packet *ssh.channelEOFMsg received: &{0}
On the server side, it appears to accept authentication and shows the
exec of the command. I also ran this using a typical openssh client as
well.
Using Go client...
sshd[13020]: Set /proc/self/oom_adj to 0
sshd[13020]: Connection from 192.168.1.101 port 45531
sshd[13020]: Postponed publickey for root from 192.168.1.101 port 45531 ssh2 [preauth]
sshd[13020]: Accepted publickey for root from 192.168.1.101 port 45531 ssh2
sshd[13020]: Found matching RSA key ...
sshd[13020]: Exec command 'echo hi'
sshd[13020]: Connection closed by 192.168.1.101
sshd[13020]: Transferred: sent 2600, received 2512 bytes
sshd[13020]: Closing connection to 192.168.1.101 port 45531
Using OpenSSH client...
sshd[12825]: Set /proc/self/oom_adj to 0
sshd[12825]: Connection from 192.168.1.101 port 36182
sshd[12825]: Postponed publickey for root from 192.168.1.101 port 36182 ssh2 [preauth]
sshd[12825]: Accepted publickey for root from 192.168.1.101 port 36182 ssh2
sshd[12825]: Found matching RSA key ...
sshd[12825]: Exec command 'echo hi'
sshd[12825]: Received disconnect from 192.168.1.101: 11: disconnected by user
Anyone else run into this or have an idea as to what is happening here?
(fwiw, I have tried commands other than "echo hi")
Dave Cheney
2011-12-12 21:19:55 UTC
Permalink
Sadly, the example code in doc.go is out of date wrt +tip. I think you've found a bug but you should try this code none the less.

To read from stdout on the remote process either call StdoutPipe() on the session or set session.Stdout to an io.Writer to collect the output. A bytes.Buffer is pretty good for this, especially with its String() method.

See if that helps, looking at the difference between go and openssh client, it looks like the server is closing the connection on the go client prematurely.

Cheers

Dave

Sent from my iPhone
Following the example client code for exp/ssh, I am getting this message after doing a session.Run("echo hi").
code...
session1, err := client.NewSession()
if err != nil {
log.Fatal("Error creating session1: ", err)
}
log.Println("Session1 created.")
if err := session1.Run(*cmdString); err != nil {
log.Fatal("Failed to Run: " + err.Error())
}
reader := bufio.NewReader(session1.Stdin)
line, _, _ := reader.ReadLine()
fmt.Println(line)
session1.Close()
Failed to Run: wait: unexpected packet *ssh.channelEOFMsg received: &{0}
On the server side, it appears to accept authentication and shows the exec of the command. I also ran this using a typical openssh client as well.
Using Go client...
sshd[13020]: Set /proc/self/oom_adj to 0
sshd[13020]: Connection from 192.168.1.101 port 45531
sshd[13020]: Postponed publickey for root from 192.168.1.101 port 45531 ssh2 [preauth]
sshd[13020]: Accepted publickey for root from 192.168.1.101 port 45531 ssh2
sshd[13020]: Found matching RSA key ...
sshd[13020]: Exec command 'echo hi'
sshd[13020]: Connection closed by 192.168.1.101
sshd[13020]: Transferred: sent 2600, received 2512 bytes
sshd[13020]: Closing connection to 192.168.1.101 port 45531
Using OpenSSH client...
sshd[12825]: Set /proc/self/oom_adj to 0
sshd[12825]: Connection from 192.168.1.101 port 36182
sshd[12825]: Postponed publickey for root from 192.168.1.101 port 36182 ssh2 [preauth]
sshd[12825]: Accepted publickey for root from 192.168.1.101 port 36182 ssh2
sshd[12825]: Found matching RSA key ...
sshd[12825]: Exec command 'echo hi'
sshd[12825]: Received disconnect from 192.168.1.101: 11: disconnected by user
Anyone else run into this or have an idea as to what is happening here? (fwiw, I have tried commands other than "echo hi")
Loading...