Ssh for cron: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 6: | Line 6: | ||
I'll be setting up a trust relationship between two machines to allow a daily sync between directories on the two machines. The machine initiating the sync is hostA. The machine acting as backup is hostB. | I'll be setting up a trust relationship between two machines to allow a daily sync between directories on the two machines. The machine initiating the sync is hostA. The machine acting as backup is hostB. | ||
===Create an appropriate key on hostA=== | ===Create an appropriate key on hostA=== | ||
ssh-keygen -t dsa -f sync-key | ssh-keygen -t dsa -f /home/user/.ssh/sync-key | ||
In this case, I'll leave the passphrase blank. | In this case, I'll leave the passphrase blank. | ||
===Copy the key to hostB=== | ===Copy the key to hostB=== | ||
Append the public key (sync-key.pub) to the end of ~/.ssh/authorized_keys on hostB | Append the public key (sync-key.pub) to the end of ~/.ssh/authorized_keys on hostB |
Revision as of 18:44, 9 September 2009
I want to allow certain systems to communicate securely using the least privileges. SSH allows me to do that, even when the communication is initiated through cron.
See this article for reference: http://www.linuxjournal.com/article/8257
I'll be setting up a trust relationship between two machines to allow a daily sync between directories on the two machines. The machine initiating the sync is hostA. The machine acting as backup is hostB.
Create an appropriate key on hostA
ssh-keygen -t dsa -f /home/user/.ssh/sync-key
In this case, I'll leave the passphrase blank.
Copy the key to hostB
Append the public key (sync-key.pub) to the end of ~/.ssh/authorized_keys on hostB
Limit the use of this key
Put these parameters into authorized_keys before the new public key.
from="hostA,hostB",command="/bin/myscript.sh",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty
Use the key
Use the key from within cron on hostA like this:
30 11 * * * rsync -avz -e "ssh -i /full/path/to/sync-key" --exclude="CVS" /home/rday/doc weasel:/home/rday/