执行某些命令后 Ssh 挂起

执行某些命令后 Ssh 挂起

我通过 ssh 运行了一些命令:ssh root@remote "SOME_COMMAND",但是命令完成后 ssh 没有返回。它只是挂在那里。

客户端ssh日志:

debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug2: channel 0: rcvd eow
debug2: channel 0: chan_shutdown_read (i0 o0 sock -1 wfd 4 efd 6 [write])
debug2: channel 0: input open -> closed
debug3: send packet: type 80
debug3: receive packet: type 82
debug3: send packet: type 80
debug3: receive packet: type 82

来自 sshd 的日志:

2024-03-03T03:24:34.988431+00:00 self sshd[26283]: debug2: channel 0: read<=0 rfd 12 len 0
2024-03-03T03:24:34.988518+00:00 self sshd[26283]: debug2: channel 0: read failed
2024-03-03T03:24:34.988559+00:00 self sshd[26283]: debug2: channel 0: chan_shutdown_read (i0 o0 sock -1 wfd 12 efd 14 [read])
2024-03-03T03:24:34.988600+00:00 self sshd[26283]: debug2: channel 0: input open -> drain
2024-03-03T03:24:34.988635+00:00 self sshd[26283]: debug2: channel 0: ibuf_empty delayed efd 14/(0)
2024-03-03T03:24:34.988671+00:00 self sshd[26283]: debug2: notify_done: reading
2024-03-03T03:24:34.988706+00:00 self sshd[26283]: debug1: Received SIGCHLD.
2024-03-03T03:24:34.988740+00:00 self sshd[26283]: debug1: session_by_pid: pid 26284
2024-03-03T03:24:34.988775+00:00 self sshd[26283]: debug1: session_exit_message: session 0 channel 0 pid 26284
2024-03-03T03:24:34.988813+00:00 self sshd[26283]: debug2: channel 0: request exit-status confirm 0
2024-03-03T03:24:34.988849+00:00 self sshd[26283]: debug3: send packet: type 98
2024-03-03T03:24:34.988882+00:00 self sshd[26283]: debug1: session_exit_message: release channel 0
2024-03-03T03:24:34.988916+00:00 self sshd[26283]: debug2: channel 0: write failed
2024-03-03T03:24:34.988950+00:00 self sshd[26283]: debug2: channel 0: chan_shutdown_write (i1 o0 sock -1 wfd 11 efd 14 [read])
2024-03-03T03:24:34.988984+00:00 self sshd[26283]: debug2: channel 0: send eow
2024-03-03T03:24:34.989022+00:00 self sshd[26283]: debug3: send packet: type 98
2024-03-03T03:24:34.989055+00:00 self sshd[26283]: debug2: channel 0: output open -> closed
2024-03-03T03:24:34.989089+00:00 self sshd[26283]: debug2: channel 0: ibuf_empty delayed efd 14/(0)
2024-03-03T03:24:34.989123+00:00 self sshd[26283]: debug2: channel 0: ibuf_empty delayed efd 14/(0)
2024-03-03T03:24:38.727125+00:00 self sshd[3758]: debug3: receive packet: type 2
2024-03-03T03:24:38.727213+00:00 self sshd[3758]: debug3: Received SSH2_MSG_IGNORE
2024-03-03T03:25:05.790042+00:00 self sshd[30063]: debug3: receive packet: type 2
2024-03-03T03:25:05.790129+00:00 self sshd[30063]: debug3: Received SSH2_MSG_IGNORE
2024-03-03T03:25:34.218472+00:00 self sshd[26283]: debug3: receive packet: type 80
2024-03-03T03:25:34.218559+00:00 self sshd[26283]: debug1: server_input_global_request: rtype [email protected] want_reply 1
2024-03-03T03:25:34.218607+00:00 self sshd[26283]: debug3: send packet: type 82

服务器日志“ibuf_empty delayed efd”看起来很可疑。但我在网上没有找到任何有用的信息。

答案1

ssh 执行的命令是一个脚本。事实证明它包含一些在后台运行的命令:

CMD_Background &

我把它们改成:

CMD_Background 2>&1 </dev/null &

通过重定向 STD IO,挂起问题已修复。看来 ssh 拒绝丢失来自后台作业或发送到后台作业的任何数据。

相关内容