通过ssh传递$ PS1

时间:2016-08-01 13:58:02

标签: linux bash ssh

我无法找到答案,但是有很多类似的问题。我想根据远程主机改变我的linux命令提示符的颜色我有ssh to。因为bash环境变量不会保留在ssh上,所以我怎么能这样做。每天都有数百台服务器登录。所以每个远程主机的更改/.bashrc是不可能的。有一种方法我可以拉出一个脚本,每次ssh完成时都可以调用。有人请详细说明哪个文件以及如何编辑它。不支持.gnome,openssh等。

2 个答案:

答案 0 :(得分:0)

"由于bash环境变量未通过ssh保留..."

man ssh

 Additionally, ssh reads ~/.ssh/environment, and adds lines of the format
     “VARNAME=value” to the environment if the file exists and users are
     allowed to change their environment.  For more information, see the
     PermitUserEnvironment option in sshd_config(5).

答案 1 :(得分:0)

在ssh执行期间,执行了一个新的登录shell。 在shell登录期间,* rc文件不会被执行,只执行了* profile。

所以请将您的代码放在 / etc / profile 〜/ .bash_profile 中。