![交互式 SSH 在 Mac 主机上运行,但通过 SSH 的 SCP 和非交互式命令失败?](https://linux22.com/image/1534870/%E4%BA%A4%E4%BA%92%E5%BC%8F%20SSH%20%E5%9C%A8%20Mac%20%E4%B8%BB%E6%9C%BA%E4%B8%8A%E8%BF%90%E8%A1%8C%EF%BC%8C%E2%80%8B%E2%80%8B%E4%BD%86%E9%80%9A%E8%BF%87%20SSH%20%E7%9A%84%20SCP%20%E5%92%8C%E9%9D%9E%E4%BA%A4%E4%BA%92%E5%BC%8F%E5%91%BD%E4%BB%A4%E5%A4%B1%E8%B4%A5%EF%BC%9F.png)
我有两台 Mac,均通过“系统偏好设置”>“共享”>“远程登录:开启”启用了 sshd。我可以成功登录这两台 Mac,并使用以下命令在交互式 shell 中运行命令
$ ssh <hostname>.local
我正在使用简单密码验证(没有 SSH 密钥),并且已确认sudo sshd -t
没有问题sshd_config
。
但是,如果我尝试在远程机器上仅执行一条命令,
$ ssh <hostname>.local echo foo
命令失败(IE,退出状态 1 / 没有任何内容STDOUT
)。具体来说,详细(调试)输出似乎看起来几乎与我在 Linux VPS 上成功执行该命令时得到的结果相同 — — 唯一的区别是退出状态:
Mac主机
$ ssh -v <hostname>.local echo foo 2>&1 | tail -n10
Password:
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: echo foo
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 1 clearing O_NONBLOCK
Transferred: sent 2300, received 2552 bytes, in 0.0 seconds
Bytes per second: sent 86838.6, received 96353.1
debug1: Exit status 1
Linux VPS 主机
$ ssh -v <vps> echo foo 2>&1 | tail
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: echo foo
foo
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 1 clearing O_NONBLOCK
Transferred: sent 3304, received 2744 bytes, in 0.3 seconds
Bytes per second: sent 11505.5, received 9555.4
debug1: Exit status 0
此外, 也scp
失败了lost connection
。
这里发生了什么?