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

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

终端报错信息(以Debian 11 系统为例):protocol version mismatch — is your shell clean?
系统环境
  • 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?"

  • 【原因】:rsync等工具非常依赖于shell执行时没有任何输出。

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

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

.profile 引用 .bashrc:

1
2
3
4
5
if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi

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

1
2
3
4
5
6
7
8
9
10
# ~/.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

1
2
3
4
5
6
7
if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi

neofetch

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

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

https://www.defense.ink/954c81e2.html

Author

Jack Liu

Posted on

2023-06-15

Updated on

2024-02-17

Licensed under