Remote console via SSH with own bashrc

Published 8/9/2017 by e0ne in Linux
Tags: , ,

I think, most of us have customized bash or zsh environment. I'm too lazy to switch from bash to zsh, so I use bash on my laptop. There are some benefits: bash is still the more popular shell, so it exists on mostly Linux-based servers.

That's why I try to use my `.bashrc` wherever it's possible. But on a remote server, sometimes you don't have the own user account. That's why I've added a very simple alias for `ssh` command to mine `.bashrc` file:

function ssh() {
  BASH_RC=`cat ${HOME}/.bashrc | base64`
  `which ssh` -t $@ "echo \"${BASH_RC}\" | base64 --decode > /tmp/${USER}_bashrc; bash --rcfile /tmp/${USER}_bashrc; rm /tmp/${USER}_bashrc"
}

It will create temporary file with your `.bashrc` content on a remote host and remove it once the session ends. The backside of this solution is your ssh connection will start with some delay to copy your`.bashrc` file to the remote host. It's not an issue for me now and I'm happy this.

The next step is to make the same with `.vimrc` with all needed plugins.