Linux login shell信息展示类(neofetch、motd等banner类提示信息展示)导致的rsync服务不可用问题注意事项

400 阅读1分钟
终端报错信息(以Debian 11 系统为例):protocol version mismatch — is your shell clean?

原文链接 by ljq@GitHub

系统环境
  • OS: Debian GNU/Linux 11 (bullseye) x86_64

  • Host: KVM RHEL 7.6.0 PC (i440FX + PIIX, 1996)

  • Kernel: 5.10.0-22-amd64

  • 【问题】:导致rsync服务同步失败,报错信息: "protocol version mismatch — is your shell clean?"

login shell载入文件信息相关文件:
/etc/profile
~/.profile

.profile 引用 .bashrc:

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

输出展示信息放在~/.bashrc文件内引发的问题(rsync为例):

# ~/.bashrc: executed by bash(1) for non-login shells.

# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022

# problem(rsync):protocol version mismatch — is your shell clean?
neofetch

【问题】:导致rsync服务同步失败,报错信息: "protocol version mismatch — is your shell clean?"。 【原因】:rsync等工具非常依赖于shell执行时没有任何输出。

【建议】:不建议在.bashrc中输出neofetch、banner类和motd类提示信息,在~/.profile中source ~/.bashrc可以避免此问题,但需注意.profile循环引用执行问题。

例如: ~/.profile

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

neofetch

总结

在Linux发行版系统中,一些高度依赖.bashrc的系统工具或者命令(例如rsync),会引发不可执行或者执行有误等问题,要留意Linux文件加载的顺序以及执行规则。

原文链接 by ljq@GitHub

相对来说,个人觉得Linux内核服务器社区发行版里,除了CentOS之外,生态体系上来说Debian OS做得不错,而终端UI操作系统 Manjaro OS的支持相对最佳。