Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 4 down vote accepted

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.

share|improve this answer
    
See also serverfault.com/a/56181/120953, for setting the command in ~/.ssh/authorized_keys so that you don't have to specify it client-side. –  Adam Sharp Mar 19 '13 at 1:01

You can add the commands to the file:

~/.bashrc

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

share|improve this answer
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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