You can use the approach described at https://serverfault.com/a/400782
You will have to use PermitLocalCommand and LocalCommand to accomplish that.
I think that solution is Ok, but I didn't like it since it will replace the .bashrc of the remote machine by
scping my local .bashrc to the remote .bashrc. Also I couldn't make it work exactly as I expected.
Another solution is to use git to manage all your dot files, like described in
But a great problem for me is that I would have to setup each server with my dot files. Even If I had the time (and patience) to deploy my dot files to each server, I would still have one problem.
Imagining a context where more than one user login to the same server using the same login, it would be unfair to change the server defaults to my defaults.
So, I developed my own solution for that, hope you like it and find it useful:
You will need to:
- Create a (private) gist at https://gist.github.com/ of your .bashrc
- You will need a login at github to create a gist
- Pay attention to sensitive informations like passwords in .bashrc enviroment variables. Anyway that kind of info should'nt be there in the first place.
- Take not for the name you gave for the gist file. I will call this GISTNAME. Choose a name that is unlikely to find in the remote dir. Don't name it ".bashrc" please. =) A good name would be
- After saving the gist, get the raw version link of it by clicking on the
<> button. You will need this link, the raw gist link or RAWGISTLINK
Then in your local
.bashrc put the following at the end:
ssh $@ -t 'cd $HOME ;
wget --quiet -N "RAWGISTLINK" ;
cp GISTNAME .'$USER'bashrc ;
bash --rcfile $HOME/.'$USER'bashrc'
Remember to replace GISTNAME and RAWGISTLINK
And then just use
customssh (you'll still have the regular
Just try one of your aliases now!
- Yes, this will probably download the gist file in every login, but believe me, it's REALLY fast. Don't worry.
- To update the shared .bashrc
- Go the the gist url, and make your changes (or copy your local
.bashrc to it).
- Then update customssh function replacing RAWGISTLINK
with the new RAWGISTLINK (the gist link and GISTNAME is the same,
but raw gist link changes when you make changes to the file).
- Now just run
source ~/.bashrc. That's it! No need to change anything
in your remote servers!
- My solution is entirely Ubuntu based, maybe it'll need some adjustments to make it work with other distros
- You probably can use other services like gist instead of github's gist. Pastebin is one example, but there are others. It's entirely possible but I haven't tried it yet.
- Also you could
wget your custombashrc.sh from other places. A public webserver for example.
- Another option, if your local machine is visible in the internet through ssh, you could just
scp the file from local server (using the public address) to the remote server. I didn't use this solution because it's hard to assume that your local machine won't be hidden behind a router or firewall (In my case, I'm behind a router)
- Maybe you can find issues across different versions of ubuntu, but I couldn't come across them yet.
The best thing about this approach is that it changes nothing in the remote servers and with little effort in the local machine and with gist you get all the fun of your local .bashrc in any server that you want.
And you still can easily "disable" this by using
ssh instead of