ssh远程环境变量不生效

场景:

服务有时候需要远程启动,这种情况下,我们配置到 /etc/profile, ~/.bash_profile的环境变量就不生效了

解决方案:

1、使用ansible也不行,查了下ansible底层主要也是通过ssh来操作的

2、看到别的帖子说把环境变量写到~/.bash_rc, 这个行得通,但是改动可能比较多,需要把/etc/profile, ~/.bash_profile的环境变量全都拷贝过来,而且每台服务器都得操作

3、最终选择的方案,在应用启动的脚本里加上

source /etc/profile
source ~/.bash_profile

你可能感兴趣的:(linux,ssh,bash,linux)