I'm trying to trigger the following command after "ssh somehost":
export PROMPT_COMMAND='echo -ne "\033]0;$HOSTNAME\007"'
nothing seems to work, any suggestions?
I do not think that can be done.
First of all I had to rewrite your command; though this is voided by the fact (see later) that what you wish to obtain cannot be achieved, yet the method to do so is of some interest and generality, so I will discuss it. I had to change your command to
ssh me@remote 'COLOR=("echo" "-ne" "\"\\033[48;5;95;38;5;214m\$HOSTNAME\033[0m\""); export PROMPT_COMMAND=${COLOR[@]}'
The reason is that it is necessary to prevent the local shell to substitute to $HOSTANME
its local
value, hence what we pass to the remote server must be wrapped in single quotes, '. For this to work, there must be no single quotes inside the command to pass, so I had to rewrite it in such a way that no single quotes appear in he command to be executed remotely. I managed to do this with an array, COLOR
. The command
COLOR=("echo" "-ne" "\"\\033[48;5;95;38;5;214m\$HOSTNAME\033[0m\"") export PROMPT_COMMAND=${COLOR[@]}
works fine locally (the choice of colors is mine).
There are two ways to export environment variables via ssh. First, one can change the variable AcceptEnv
in the server's /etc/ssh/sshd_config
file: but the manual states
AcceptEnv
Specifies what environment variables sent by the client will be copied into the session's environ.
The emphasis here is on the session: no global change.
The second way is thru the PermitUserEnvironment
variable:
PermitUserEnvironment
Specifies whether ~/.ssh/environment and environment= options in ~/.ssh/authorized_keys are processed by sshd. The default is "no". Enabling environment processing may enable users to bypass access restrictions in some configurations using mechanisms such as LD_PRELOAD.
As you can see, ssh
is quite careful in not allowing a remote user to change global environment variables.
ssh root@MachineB 'bash -s' < local_script.sh
to run the contents oflocal_script.sh
after connecting toMachineB
.