I couldnt find answer to this althougth there are many similar questions.I wanted to change colour of my linux command prompt based on the remote host i have ssh to.Since bash environment variables are not preserved over ssh,so how could i do this.There are hundreds of server i login everyday.So changing /.bashrc of each remote host is not possible.is there a way i can pullout a script which can be called each time ssh is done.Can someone please give in detail of which file and how it should be edited.gnome,openssh etc are not supprted.
Asked
Active
Viewed 1,798 times
0
-
You could use something like `ssh host "PS1=$PS1 bash"`, but any configuration files on the remote end that configure `PS1` will almost certainly not check to see if `PS1` is already set. – chepner Aug 01 '16 at 14:12
-
2See: [Can I forward env variables over ssh?](http://stackoverflow.com/q/4409951/3776858) – Cyrus Aug 01 '16 at 14:32
-
1But what I m looking for is a change in a conf file or something like that or some script which can be called everytime i ssh,without a change in d way I use SSH command... – Barca-15 Aug 01 '16 at 15:24
2 Answers
1
during ssh execution,a new login shell was executed. during shell login the *rc files are not executed,only *profile was executed.
so place your code in /etc/profile or ~/.bash_profile.

purushothaman poovai
- 314
- 1
- 12
0
"Since bash environment variables are not preserved over 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).

Ipor Sircer
- 3,069
- 3
- 10
- 15
-
1This only works if the server's configuration has enabled PermitUserEnvironment , which is off by default. – Barca-15 Aug 01 '16 at 15:21