我可以通过 ssh 正常进入的服务器现在开始拒绝 scp。
$ scp ~/tmp/foo [email protected]:~/tmp/
lost connection
我scp -v -v
可以看到连接成功并且传输似乎成功,但是另一端没有出现任何文件。
OpenSSH_5.9p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /Users/schwern/.ssh/config
debug1: /Users/schwern/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to testcurrent01.dev.liquidweb.com [10.30.152.254] port 22.
debug1: Connection established.
debug1: identity file /Users/schwern/.ssh/id_rsa type -1
debug1: identity file /Users/schwern/.ssh/id_rsa-cert type -1
debug1: identity file /Users/schwern/.ssh/id_dsa type -1
debug1: identity file /Users/schwern/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
...lots of authentication details...
debug1: Enabling compression at level 6.
debug1: Authentication succeeded (publickey).
Authenticated to [email protected] ([1.2.3.4]:22).
debug2: fd 5 setting O_NONBLOCK
debug2: fd 6 setting O_NONBLOCK
debug1: channel 0: new [client-session]
debug2: channel 0: send open
debug1: Entering interactive session.
debug2: callback start
debug2: client_session2_setup: id 0
debug2: fd 3 setting TCP_NODELAY
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug2: channel 0: request env confirm 0
debug1: Sending command: scp -v -t -- ~/tmp/
debug2: channel 0: request exec confirm 1
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug2: channel 0: rcvd close
debug2: channel 0: close_read
debug2: channel 0: input open -> closed
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
Transferred: sent 4576, received 2520 bytes, in 0.0 seconds
Bytes per second: sent 167737.0, received 92372.6
debug1: Exit status 0
debug1: compress outgoing: raw data 135, compressed 121, factor 0.90
debug1: compress incoming: raw data 66, compressed 52, factor 0.79
lost connection
它是一台 CentOS 5.9 机器。
我已检查过的事情...
- 我有写入该目录的权限。
- 用户有一个合理的shell(/bin/bash)。
- 我尝试移开
~/.ssh/config
视线。 - 从其他具有完全不同操作系统的机器上 scp 操作也会失败。
- 磁盘未满。
- 重新启动 sshd。
/var/log/secure 包含...
Apr 4 14:23:22 some sshd[12576]: Postponed publickey for user from 1.2.3.4 port 33581 ssh2
Apr 4 14:23:22 some sshd[12575]: Accepted publickey for user from 1.2.3.4 port 33581 ssh2
Apr 4 14:23:22 some sshd[12575]: pam_unix(sshd:session): session opened for user user by (uid=0)
Apr 4 14:23:22 some sshd[12575]: pam_unix(sshd:session): session closed for user user
我下一步应该检查什么?
答案1
遇到了同样的问题。
如果您进行了 Centos 的最小安装,它只会安装openssh
和openssh-server
包而不会安装openssh-clients
。sudo yum install openssh-clients
这将解决您的问题。
答案2
scp
通过调用ssh
程序与远程主机建立连接,并scp
在该主机上启动该程序的另一个副本来工作。两个 scp 实例通过 ssh 连接进行通信以执行文件传输。
当 ssh 连接过早断开时,本地scp
程序会打印“丢失连接”。通常的原因是scp
远程主机上的程序无法启动或过早退出。这可能是因为远程主机上不存在 scp 程序,或者它不在您的命令 PATH 中,或者它未标记为可执行文件,或者它在启动后崩溃,或者类似情况。
答案3
如果您恰好正在运行 ufw 包并且设置了端口 22 sudo ufw limit 22
,则需要使用以下命令打开它:
sudo ufw allow 22
使用以下方式检查状态:
sudo ufw status
答案4
我们的一个系统最近遇到了这个问题。
我们可以正确地通过 ssh 连接到主机服务器,但发现我们无法从服务器通过 ssh 连接到机器。这是一个值得研究的地方,如果你不能做到这一点,那么你将无法使用 SCP。
在我们的案例中,不知何故(可能是安装不当)将我们的 ssh 二进制文件替换为 0 字节空文件。每当执行“ssh”时,什么也不会发生。
通过重新安装 openssh-clients,我们纠正了二进制文件并且 scp 开始工作。
yum reinstall openssh-clients