Skip to main content

Posts

Showing posts from September, 2015

Using ssh-agent for Unattended Batch jobs with Ssh Key Passphrase

In some cases, It is needed to make ssh connections to another servers in order to run shell commands on them remotely. But when it comes to run these commands from a cron job, password interaction will be a concern. Using ssh key-pair with an empty passphrase may be an option but it is not recommended. There is another option automates passphrase interaction.
Ssh-agent provides a storage for unencrypted key because the most secure place to store a key is in program memory.
I am going to explain how to run batch/cron shell script integrated with ssh-agent:
There are two servers, server1 and server2.
On server1, ssh key pair is created.
# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): <your passphrase here> Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: ........
On server2 copy content of the id_rsa.pub file from server1 and insert it to /roo…