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?


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.

| improve this answer | |

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.