One of the key tools for ssh automation is keychain, which is pretty much available in most flavors of linux. Its usually not installed by default, therefore using your package manager install ‘keychain’
Ubuntu users:
$sudo apt-get install keychain
After its install, you set it up by entering the keychain command followed by your private key (not the public key).
$ keychain ~/.ssh/id_rsa
KeyChain 2.6.6; http://www.gentoo.org/proj/en/keychain/ Copyright 2002-2004
Gentoo Foundation; Distributed under the GPL</pre>
* Initializing /home/timmy/.keychain/hostname-sh file...
* Initializing /home/timmy/.keychain/hostname-csh file...
* Initializing /home/timmy/.keychain/hostname-fish file...
* Starting ssh-agent
* Adding 1 ssh key(s)...
Enter passphrase for /home/timmy/.ssh/id_rsa:
Identity added: /home/timmy/.ssh/id_rsa (/home/timmy/.ssh/id_rsa)
Keychain then creates three files which correspond to various shell environments. As I am using bash, the file I will be referencing will be /home/timmy/.keychain/hostname-sh.
$ source ~/.keychain/hostname-sh
To make sure everything is fine run the following to make sure the the environment is in fact set up:
$ env | grep SSH_A
SSH_AGENT_PID=9607
SSH_AUTH_SOCK=/tmp/ssh-bMoLeb9606/agent.9606
Of course you will want this to happen automatically on login so add the following to your ~/.bashrc
keychain ~/.ssh/id_rsa
source ~/.keychain/hostname-sh
The last step is to add the following line to your backup script (including the .)
. /home/timmy/.keychain/hostname-sh
Backup Scripts
Ill only mention the two methods that i use.
1. scp: To copy files from one location to another
2. rsync: To sync a remote location to local location
Read the rest of this entry »