Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/crypto/ssh: Session.Run returns error EOF #28108

Closed
QijingLi opened this issue Oct 9, 2018 · 7 comments
Closed

x/crypto/ssh: Session.Run returns error EOF #28108

QijingLi opened this issue Oct 9, 2018 · 7 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@QijingLi
Copy link

QijingLi commented Oct 9, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go1.10 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

darwin and amd64

What did you do?

I'm trying to run command on the device through ssh. I got same error with closed issue.
#16194

I tried changing WantReply to false. it didn't work.
please see the last comment.

What did you expect to see?

no error

What did you see instead?

error

@ianlancetaylor ianlancetaylor changed the title Session.Run() returns error EOF x/crypto/ssh: Session.Run returns error EOF Oct 10, 2018
@gopherbot gopherbot added this to the Unreleased milestone Oct 10, 2018
@ianlancetaylor
Copy link
Contributor

Please tell us exactly what you did: what program did you run, what was the complete output? Thanks.

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 10, 2018
@QijingLi
Copy link
Author

QijingLi commented Oct 10, 2018

this is the code i run against some device which implements SSH server.

	var sshConfig ssh.Config
	sshConfig.SetDefaults()
	sshConfig.Ciphers = append(sshConfig.Ciphers, "aes128-cbc", "aes256-cbc", "3des-cbc")
	fmt.Println("cipers:", sshConfig.Ciphers)
	config := &ssh.ClientConfig{
		Config: sshConfig,
		User:   login.Username,
		Auth: []ssh.AuthMethod{
			ssh.Password(login.Password),
		},
		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
		Timeout:         timeout,
	}
	if client, err = ssh.Dial("tcp", "192.168.0.10:22", config); err != nil {
		err = errors.New("unable to connect: " + err.Error())
		return
	}
	defer client.Close()
	if session, err = client.NewSession(); err != nil {
		err = errors.New("unable to open session" + err.Error())
		return
	}
	defer session.Close()

	// start to run command show macs
	var streamOut io.Reader
	if streamOut, err = session.StdoutPipe(); err != nil {
		err = errors.New("unable to make stdpipe connected: " + err.Error())
		return
	}
	if err = session.Run("show mac addresses"); err != nil {
		err = errors.New("unable to run the command:"+ err.Error())
		return
	}

The program returns the following:

unable to run the command: EOF.

After I enabled debugMux variable

018/10/10 14:19:17 send global(1): ssh.channelOpenMsg{ChanType:"session", PeersID:0x1, PeersWindow:0x200000, MaxPacketSize:0x8000, TypeSpecificData:[]uint8(nil)}
2018/10/10 14:19:17 decoding(1): 91 &ssh.channelOpenConfirmMsg{PeersID:0x1, MyID:0x1, MyWindow:0x1000, MaxPacketSize:0x1000, TypeSpecificData:[]uint8{}} - 17 bytes
2018/10/10 14:19:17 send(1): ssh.channelRequestMsg{PeersID:0x1, Request:"exec", WantReply:true, RequestSpecificData:[]uint8{0x0, 0x0, 0x0, 0x10, 0x73, 0x68, 0x6f, 0x77, 0x20, 0x63, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x6d, 0x6f, 0x64, 0x65, 0x6d}}
2018/10/10 14:19:17 decoding(1): data packet - 28 bytes
2018/10/10 14:19:17 decoding(1): data packet - 264 bytes
2018/10/10 14:19:17 decoding(1): data packet - 173 bytes
2018/10/10 14:19:17 decoding(1): data packet - 120 bytes
2018/10/10 14:19:17 decoding(1): data packet - 120 bytes
2018/10/10 14:19:17 decoding(1): data packet - 129 bytes
2018/10/10 14:19:17 decoding(1): data packet - 129 bytes

after changed WantReply to false in Start function in session.go

2018/10/10 14:34:27 send global(1): ssh.channelOpenMsg{ChanType:"session", PeersID:0x1, PeersWindow:0x200000, MaxPacketSize:0x8000, TypeSpecificData:[]uint8(nil)}
2018/10/10 14:34:27 decoding(1): 91 &ssh.channelOpenConfirmMsg{PeersID:0x1, MyID:0x1, MyWindow:0x1000, MaxPacketSize:0x1000, TypeSpecificData:[]uint8{}} - 17 bytes
2018/10/10 14:34:27 send(1): ssh.channelRequestMsg{PeersID:0x1, Request:"exec", WantReply:false, RequestSpecificData:[]uint8{0x0, 0x0, 0x0, 0x10, 0x73, 0x68, 0x6f, 0x77, 0x20, 0x63, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x6d, 0x6f, 0x64, 0x65, 0x6d}}
2018/10/10 14:34:27 send(1): ssh.channelEOFMsg{PeersID:0x1}
2018/10/10 14:34:27 decoding(1): 96 &ssh.channelEOFMsg{PeersID:0x1} - 5 bytes
2018/10/10 14:34:27 decoding(1): 97 &ssh.channelCloseMsg{PeersID:0x1} - 5 bytes
2018/10/10 14:34:27 send(1): ssh.channelCloseMsg{PeersID:0x1}
2018/10/10 14:34:27 send(1): ssh.channelCloseMsg{PeersID:0x1}
2018/10/10 14:34:27 loop exit read tcp 10.172.58.120:61108->192.168.0.10:22: use of closed network connection
{"level":"error","time":"2018-10-10T14:34:27.445-0700","message":"failed to fetch the MACs","error":"unable to run the command: wait: remote command exited without exit status or exit signal"}

@QijingLi
Copy link
Author

here is comment from @hanwen
Our library is waiting for the exit-status or exit-signal message, which isn't coming. According to RFC 4254, those are optional, so we should probably do something intelligent in case the remote end doesn't send a status message. --

I have a question here. if the server doesn't send message when the command finishes, how the ssh client knows when it finish?

@hanwen
Copy link
Contributor

hanwen commented Oct 16, 2018

The first trace looks OK; data is going over the wire.

Why did you change wantReply? That would likely cause the remote end to error out.

@QijingLi
Copy link
Author

on the first trace, it ended up with returning EOF. The ssh client didn't get any data.
After reading this issue #16194, it looks exactly same.
the reason cause returning EOF is the server side didn't send the message when it's done the work,
but client want a reply. So I tried to change wantReply.

@hanwen
Copy link
Contributor

hanwen commented Oct 16, 2018

the debugMux output looks completely different.

@QijingLi
Copy link
Author

QijingLi commented Oct 16, 2018

@hanwen got it working. thanks for your reply!
In my case, EOF actually is the sign of the server side finish the work.

@QijingLi QijingLi closed this as completed Mar 7, 2019
@golang golang locked and limited conversation to collaborators Mar 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants