I frequently connect to servers through a user I share with other colleagues, every time I connect to each server I execute a couple of commands like bash, set -o vi, etc.

I would want to know if there is a way to tell the ssh client utility to execute those on the remote server before handing me the control.

Basically something like this:

echo "bash; set -o vi; <DONT_EXIT>;" | ssh user@host

Anything built in the ssh client utility? Any workarounds that are executed from MY side? I am aware of workarounds on the server side, which are not what I am looking for. I can't find this anywhere, so, I am basically confirming that it actually can't be done.

I am using Linux with the default OpenSSH ssh utility.


The parameter I was looking for is: -t which would force the ssh client to allocate a terminal , so it looks like this:

ssh -t user@host "bash -o vi"

This will get me to auto enable the vi mode upon connect, but executing more commands is trickier since if I added more commands afterwards they will be executed after exit from bash and immediately exit everything, so all commands must be executed before it.


You can add the commands to the file:


when you login, first execute these commands, last it give you the shell.

  • 1
    That has to be done server-side, and would affect the other colleagues who share the account. – Ben Voigt Jan 3 '13 at 17:25

Perhaps finish off your string of commands with your shell you want to interact with?

ssh user@host "bash -c 'set -o vi; bash'"

I tested this and it seems to run the initial commands and then be interactive, however stdout isn't coming back properly. Hopefully someone else can point out the solution to that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.