分类: LINUX
2015-01-13 17:46:27
原文地址:当使用sftp或者scp时出现错误解决办法。 作者:godmoney
Received message too long (or "Bad packet length")
1399791731
。
$ sftp user@yourIP
Connecting to XX.XX.XX.XX...
user@XX.XX.XX.XX's password:
Received message too long 1399791731
这个通常是由于在服务器端,有过多的输出造成的,例如在~/.bashrc下加入了echo命令,
$cat ~/.bashrc
So so so lag.
So so so lag.
So so so lag.
So so so lag.
这个时候就会出现以上错误。
附上ssh FAQ相关部分,
Received message too long (or "Bad packet length") 1416586337
and the connection fails. What's wrong?
ssh server -s -oForwardX11=no -oForwardAgent=no -oProtocol=2 sftp
scp2/sftp and sftp-server use a special file-transfer protocol, which they speak over this SSH session. The protocol is in fact based on the same packet protocol used by SSH.
In order for this to work, the SSH session must be "clean" — that is, it must have on it only information transmitted by the programs at either end. What often happens, though, is that there are statements in either the system or per-user shell startup files on the server (.bashrc, .profile, /etc/csh.cshrc, .login, etc.) which output text messages on login, intended to be read by humans (like fortune, echo "Hi there!", etc.). Such code should only produce output on interactive logins, when there is a tty attached to standard input. If it does not make this test, it will insert these text messages where they don't belong: in this case, polluting the protocol stream between scp2/sftp and sftp-server. The first four bytes of the text gets interpreted as a 32-bit packet length, which will usually be a wildly large number, provoking the error message above. Notice that:
1416586337 decimal = 546F6461 hex = "Toda" ASCII
suggesting a string beginning "Today..." (or maybe "Thank-you" in transliterated Hebrew).
The reason the shell startup files are relevant at all, is that sshd employs the user's shell when starting any programs on the user's behalf (using e.g. /bin/sh -c "command"). This is a Unix tradition, and has advantages: