Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to define bash functions and aliases in my remote shell automatically on login. I can't put the definitions into .profile or similar because the users I log in as are often shared with others who use the same systems and I don't have control of this. What I'm trying to do is execute a few bash function definitions in the remote process and then continue as a login shell. I tried this but it did not work:

cat ~/.profile - | ssh -tt user@host bash -l

Any ideas?

share|improve this question
This should help:… – Jason S Jun 9 '12 at 14:55
Thanks, that is what I was looking for. – Ramon Jun 9 '12 at 16:52
Great! Glad it helped. DFTBA! :) – Jason S Jun 9 '12 at 18:00

If you have permission, you could also modify the .bashrc or .bash_profile on the destination server to do a 'whoami' check and only run those alias and function settings if it matches your username.

Personally, I'd go with the Expect option, but it can be quite an exercise in frustration if not you're not already conversant with Expect.

share|improve this answer

Your Answer


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.