pycharm 远程连接服务器报错
配置远程链接的时候出现报错
Command finished with exit code 139
Execution was killed due to timeout
Failed to execute command Rsync command ‘rsync’ was not found neither in local PATH nor as full executable path Starting introspection for Python…
放假前好好的,放假后突然不行了。
锁定问题
step1 我尝试在本地 ssh / Xshell 登录都可以运行命令,说明服务器是好的;
step2 然后pycharm连接A服务器,可以运行程序,说明pycharm本身没有问题;
step3 有问题的只有pycharm连接B服务器,出现 报错139,推断:问题出在 PyCharm 用的登陆远程解释器时,触发了B服务器的某些环境脚本 bug。
解决问题
chatgpt和deepseek左脚踩右脚的提问他们,评判对方的方法是否合理并可以解决问题,最后找到了一个保险的方法解决了。
(1)首先,确定服务器有没有安装 rsync。有输出,说明安装正常。
which rsync
(2)程序xshell运行代码,必须能输出一个路径。
bash -l -c 'pwd' # 这个地方我出现了报错139
/bin/bash --noprofile --norc -c 'pwd' # 这个地方我的输出正常
加上 --noprofile --norc 后一切正常
所以真正的问题就是 PyCharm 默认用 bash -l,会加载 /etc/profile 和 /etc/profile.d/*.sh,而里面某个脚本(大概率是 /etc/profile.d/colorgrep.sh)在 非交互 login shell 下写错了逻辑,导致了崩溃 (exit 139)。
手工 ssh 登录之所以没事,是因为你得到的是 交互式 login shell,脚本执行路径不一样。
(3)修复服务器,守护模式判断
备份服务器现有 .bashrc文件;
编辑 .bashrc,在最顶部插入 guard clause;
# --- PyCharm/SSH Guard Clause ---
case $- in*i*) ;;*) return ;;
esac
# --- End Guard Clause ---
保存退出,测试 PyCharm SSH Interpreter 或:
bash -l -c 'pwd'
不会再崩溃,exit 139 消失。