实际工作例子:

在windows上用XShell工具时,某服务器长时间都没有反应。

但是ssh登录仍然可以正常连接。

换用linux上的sftp命令来连接时,出现了一些错误信息:

[root@TS-3-206 ~]# sftp -o Port=5555 root@192.168.18.15:/usr/local/gdns/

Connecting to 192.168.18.15...

root@192.168.18.15's password:

Received message too long 1131376761

原因在于服务端的.bashrc中有存在标准输出的语句

[root@pb6a817b5 etc]# cat ~/.bashrc# .bashrc

# User specific aliases and functions

alias rm='rm -i'

alias cp='cp -i'

alias mv='mv -i'

# Source global definitions

if [ -f /etc/bashrc ]; then

. /etc/bashrc

fi

source /opt/intel/vtune_amplifier_xe_2013/amplxe-vars.sh

最后一个脚本程序会输出:

Copyright (C) 2009-2014 Intel Corporation. All rights reserved.

Intel(R) VTune(TM) Amplifier XE 2013 (build 353306)

需要把这些输出去掉,因此改为

source /opt/intel/vtune_amplifier_xe_2013/amplxe-vars.sh 1>/dev/null 2>&1

根据SFTP中的相关说明,输出字符的前4个字节"Copy"每个字母按照ASCII值拼接在一起被翻译成32位整数,十六进制是436F7079,十进制就是1131376761, 在传输协议中是作为包长度字段的,因此这是一个非常大的数字,导致连接出错。

附上相关的FAQ

SSH Frequently Asked Questions

When I try to use sftp or scp2, I get a message like this:

Received message too long (or "Bad packet length") 1416586337

and the connection fails. What's wrong?

sftpandscp2both actually work by runningsshin a subprocess, to connect to the remote host and run the file-transfer server (usually namedsftp-server). For instance, the commandsftp servermight result in the following command being run (OpenSSH):

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:The user's usual setup (command aliases, environment variables, umask, etc.) are in effect when remote commands are run.

The common practice of setting an account's shell to /bin/false to disable it will prevent the owner from running any commands, should authentication still accidentally succeed for some reason.

There has been a lot of argument about whether this is the right behavior, since havingsshdinstead execsftp-serverdirectly, without the shell, would avoid this frequent problem. I personally feel that using the shell is the right thing to do: having startup files that emit text messages when there is no user to read them is just a mistake. SSH2 has a Boolean configuration statementAllowCshrcSourcingWithSubsystems, set false by default, which causessshd2to pass the-fflag to the shell when running subsystem programs (sftp-serveris run as an SSH-2 "subsystem"). With most shells,-fcauses the shell to omit the normal startup file processing. This prevents the corruption problem, but introduces other difficulties. With file transfers, the umask setting is important, and people are confused when they find that the umask they set in their~/.loginfile works with random remote commands (e.g.ssh server touch foo), but is mysteriously ignored when usingscp2/sftp.

linux服务器sftp无法连接超时,sftp连接服务器失败相关推荐

  1. icloud连接服务器时出现问题_苹果icloud连接超时怎么办 icloud服务器连接超时解决方法...

    icloud服务器连接超时解决方法: 1.进入手机的设置,选择iCloud,下移到最底选注销,这时会有提示,点确认. 2.退出iCloud后,重新按新建iCloud的方法,按提示用原来的iPhone手 ...

  2. wget 地址 连接超时_HttoPool连接池 和Hystrix 服务容错机制

    学习主题:httpPool&Hystrix 学习目标: 对应视频: http://www.itbaizhan.cn/course/id/85.html 对应文档: 无 对应作业 1. 编写支持 ...

  3. oracle池式连接超时,oracle连接由于防火墙设置导致超时的问题

    当应用程序使用数据库连接池进行数据连接时,防火墙的设置有可能会导致连接出现超时或者被重置的问题.当从数据库读数据的时候 有可能会 Connection timed out, 这是由于应用会缓存数据连接 ...

  4. conda下载出现连接超时怎么办

    conda下载出现连接超时怎么办 文章目录: 一.连接超时原因 二.解决conda下载超时的两种办法 1.添加下载镜像地址 2.conda通过参数设置修改超时时间 三.超时依旧没有解决的其他原因 一. ...

  5. Nginx高级优化(2): shell脚本日志切割,连接超时,进程数,网页压缩,防盗链,FPM 参数优化!!

    呕心沥血书写,看完后对Nginx了如执掌,不看真的后悔!! shell脚本日志分割 设置连接超时 Nginx深入优化 更改进程数 配置网页压缩 配置防盗链 20.0.0.25 主机:开始盗链 20.0 ...

  6. php 客户端socket长连接超时,[PHP] socket客户端时的超时问题

    连接socket分为连接超时和读取超时 $sock=stream_socket_client("www.google.com:80", $errno,$errstr,2);    ...

  7. Java使用SFTP和FTP两种连接服务器的方式实现对文件的上传下载

    一.Java实现对SFTP服务器的文件的上传下载: 1.添加maven依赖: <dependency><groupId>com.jcraft</groupId>&l ...

  8. linux限制普通账号使用sftp,CentOS6.2使用SFTP限制帐号SSH连接

    CentOS6.2使用SFTP限制帐号SSH连接 编辑/etc/ssh/sshd_config #vim /etc/ssh/sshd_config #Subsystem sftp /usr/libex ...

  9. SFTP连接GCP,向服务器发送文件方法,第三方工具生成密钥对连接GCP服务器(putty生成密钥远程连接服务器)...

    190223更新通过WinSCP工具导入key,向服务器发送文件方法: 很多时候需要向服务器发送文件,GCP和一般服务器不太一样,使用ftp和用户名密码不容易获取,一般采用秘钥的方式,下边介绍实现方法 ...

最新文章

  1. Spring Boot Spring MVC 异常处理的N种方法
  2. POJ 3621 最优比率生成环
  3. IdentityServer Topics(1)- 启动说明
  4. word List25
  5. Liferay7 BPM门户开发之4: Activiti事件处理和监听Event handlers
  6. java怎么进行浮点数运算_【考试经验】Java中实现浮点数的精确运算
  7. 三大重磅奖项揭晓 2020全球智博会为行业加冕
  8. 金融级IT架构-数字银行的云原生架构解析
  9. 我的前半生之六,创业维艰,我不想骂你,你滚吧
  10. 黑色星期五c语言程序,黑色星期五C语言实现
  11. 服务器虚拟资源池,虚拟资源池
  12. ybt1058 求一元二次方程
  13. MATLAB Jacobi迭代法 求解线性方程组
  14. 百度云-人工智能-识别图片中的文字
  15. 别了,亲爱的读者朋友们!!让我们别处再相逢!
  16. 特征工程 | 信息价值IV与群体稳定性PSI
  17. 英文SEO分析竞争对手推广策略实操
  18. html图片自适应上下左右居中显示,图片大小自适应垂直居中的方法
  19. http 1.php,php利用socket扩展写一个简单的单进程http服务1
  20. 软件项目范围变更流程与过程控制研究

热门文章

  1. 云原生爱好者周刊:mist.io 开源多云管理平台
  2. PC端浏览器兼容性问题解决方案
  3. 老款Mac装win10黑屏或灰屏
  4. python之excel编程
  5. 云数据库与传统数据库有什么区别
  6. python average函数详解_python基础之函数详解
  7. TApplicaiton.ProcessMessages不能在非主线程使用
  8. 华中科技大学计算机王凯,苗蕾-环境科学与工程学院
  9. And The Winner Is --- 百度网盘
  10. PPT动画制作选美大赛