Sync out of the box – Sync your bashrc using a CVS

Sync your bashrc between servers

Sync your bashrc between servers

If you work on several Unix servers you may need to keep in sync your shell profile (bashrc, kshrc, zshrc, .profile, etc).

When available on the servers, you can use Rync, or if your servers are directly connected to Internet, you can use a CVS system (bazaar, git, cvs, svn) and store your user settings, for example, on github (Using Git and Github to Manage Your Dotfiles by Smalley Creative Blog).
Obviously you can also develop a script or a software that does something similar.

A nifty alternative, sync your bashrc with ssh

When you don’t want or you cannot use one of the above methods, an alternative is to use an awesome functionality of OpenSSH.

OpenSSH allow you to set a local command to be executed every time you successfully connect to a remote host.

We can use this functionality to just execute an scp of our .bashrc on each server we connect to.

$ cat .ssh/config
Host *
PermitLocalCommand yes
LocalCommand scp -q %d/.bashrc %h:

In this example we set for all the ssh connection (Host *) that we allow ssh to execute local commands (PermitLocalCommand yes). The command is specified in the last line, where %d is substituted by the local home directory and %h by the target host.

Using Host * is not a good idea except if you have a really basic and anonymous shell profile.

I usually have Host sections in my ssh/config file based on domain names (like * and instead of a “naked” scp I advice to use a script that transfer a list of files only if they have not been synchronized previously (may be the subject of a future article)

The big advantage of using LocalCommand is that you don’t need to keep an inventory of the servers you connect to and neither setup manually all of them.