#StackBounty: #bash #ssh #zsh #source Source a file after ssh login drops to prompt

Bounty: 50

One-liner question: How do I automatically source a remote file on remote host after logging in via SSH via a bastion host?

I need to source a file containing a list of aliases + shell user defined functions on a remote host after ssh-ing into it.

The file exists on remote maching in /tmp folder e.g. /tmp/my-rc

Searching other posts and internet I have found

ssh -t user@domain.com 'source /tmp/my-rc; bash -l'

The problem is that I do get a terminal, but none of the aliases are set since it’s a new bash shell’

Thinking, that the source should be done after the shell is attached, tried the below but this also doesn’t work. There is no error, I get the terminal but don’t think the file got sourced (verified by echoing dummy message from /tmp/my-rc file)

ssh -t user@domain.com 'bash -l; source /tmp/my-rc'

Even tried with ‘.’ instead of source, no luck.

Any help.

Note1: Bash or ZSH any shell solution would do.

Note2: The actuall ssh is via a proxy command i.e. a hop over bastion host (Just mentioning if it is relevant at all)

Note3: I don’t have privilage of a profile rc or bashrc or even a home directory on the remote host.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.