I have a simple problem of needing to execute an export command over ssh, and then stay logged in, but I'm having some trouble. Though I am interested in a solution to this problem for many reasons, the main one is so I can custom set my terminal tabs to a name of my choosing.

Here's the command I have so far:

ssh -t root@somehost "export PROMPT_COMMAND=''; echo -ne '\033]0;MY_TAB_NAME'; echo -ne '\007'; /bin/bash -i"

This is quite a doozy, and I think I am just about there. The -t option opens a pty (pseudo terminal), while the /bin/bash -i opens an interactive bash session (thus staying logged in after ssh command execution. The export command simply clears out the prompt in order for the following echo to rename it.

The problem I'm having is that the export doesn't seem to be executing in the right shell. I think I am missing something pretty simple.

Also, I am trying to make this purely command-line based without having to use the various .bash files. I have hundreds of servers I connect to, and have an easy way to bookmark all the connections, but just need some way to custom name each tab in my terminal (Mac OS X, willing to use iTerm if an easier solution exists).


3 Answers 3


Perhaps you should look at using ~/.ssh/environment or the environment option in ~/.ssh/authorized_keys instead. See the sshd(8) man page for details.

ssh host -t VAR=VALUE bash --login

I have a simple problem of needing to execute an export command over ssh, and then stay logged in [...]

Just to solve your main question, without digging too much in the rest of your problem. If you want to export some variables (or other environment stuff) you can use env.

The env command lets you run a program in a modified environment. Hence you can use it to run bash -i in the remote server modifying the environment at pleasure.

I leave you just one example:

hmontoliu@laptop:~$ ssh -t remoteuser@remoteserver env EXPORTEDSTUFF='foo' MOREXPORTEDSTUFF='bar' bash -i
remoteuser@remoteserver's password: 
remoteuser@remoteserver:~$ echo $EXPORTEDSTUFF 
remoteuser@remoteserver:~$ echo $MOREXPORTEDSTUFF 

Check env's man page


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .