Ssh – How to ssh and use a personal bashrc without getting disconnected

bashssh

I would like to be able to ssh to a remote host and run some repetitive commands on it before continuing my work.

I have been trying the following command with no luck:

ssh uname@remotehost.com 'source /path/to/my/bashrc; ls /logs'  

The commands run fine, however I am not being presented with a shell to continue my work.

What am I missing here?

Best Answer

You are missing one thing. That if you provide ssh command to run, the session will end as soon as the session ends. This mean as soon as your ls command ends, also ssh will return. To achieve your requested behaviour you need to add the bash/shell to the end and request tty allocation, like this:

ssh -tt uname@remotehost.com 'source /path/to/my/bashrc; ls /logs; bash'

or you can substitute the bash command with other shell you prefer.