Linux – Use SSH to execute remote export command and stay logged in

bashcommand-line-interfacelinuxssh

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).

Thanks!

Best Answer

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.