Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to console to many machines through SSH. Including Linux, Mac, mobile devices, virtual machines. Sometimes I need to login to more than 10 machines in one day.

I enjoy my personal .bashrc or .bash_profile settings, like prompt (PS1), history control, aliases and other useful settings. But keeping these settings across many machines is nothing but pain.

So if anyone has idea how to automate this? Best would be to 'carry' the settings with me from my 'motherworld-PC'.

share|improve this question
add comment

3 Answers

One common approach to this is putting your dotfiles into github or another version control system. Not only can you easily update them, but you keep a history of the changes you've made for when you need to revert something.

Quick google searches for "dotfiles in github" and "dotfiles in version control" gave me a couple pages that look useful:

After setting this up, you could automate the updates with a cronjob on each server or simply adding a "git pull" in your .bash_profile.

share|improve this answer
add comment

You can use the approach described at http://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

http://blog.smalleycreative.com/tutorials/using-git-and-github-to-manage-your-dotfiles/

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.

Then...


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 mycustombashrc.sh
    • 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:

function customssh(){
  ssh $@ -t 'cd $HOME ; 
  wget --quiet -N "RAWGISTLINK" ;
  cp GISTNAME .'$USER'bashrc  ; 
  bash --rcfile $HOME/.'$USER'bashrc'

}

Remember to replace GISTNAME and RAWGISTLINK

Now run

source ~/.bashrc

And then just use customssh (you'll still have the regular ssh)

customssh mylogin@remoteserver

Just try one of your aliases now!

Notes

  • 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 customssh.

share|improve this answer
add comment

Something like rsync would probably fit your needs. If that's not an option, use Dropbox to sync the files across each device and create a symlink between the locally-synced file and where you would otherwise need it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.