SSH, key authentication and batch mode
Par Pierrick, vendredi 7 septembre 2007 à 16:12 / categorie: GNU/linux / tags: / #103 / rss

A long time ago, I've tried to use connect to a SSH server with my private key in a batch mode (with a cron task). I didn't find the way to do it. Now I have. It is as simple as to have no passphrase on your private key. Less secure (but still much more secure than FTP connection) but makes SSH possible in cron task.
$ ssh-keygen -t dsa Generating public/private dsa key pair. Enter file in which to save the key (/home/pierrick/.ssh/id_dsa): /home/pierrick/.ssh/id_dsa2 Enter passphrase (empty for no passphrase): Enter same passphrase again: /home/pierrick/.ssh/id_dsa2.pub. Your identification has been saved in /home/pierrick/.ssh/id_dsa2. Your public key has been saved in /home/pierrick/.ssh/id_dsa2.pub.
Add the content of /home/pierrick/.ssh/id_dsa2.pub into remote ~/.ssh/authorized_keys
$ export EDITOR=vi; crontab -e * * * * * ssh -i /home/pierrick/.ssh/id_dsa2 remote_user@remote_server 'echo $(date) >> /tmp/pierrick.log'
And see that every second, the date is appended to the remote /tmp/pierrick.log
Commentaires
1. Le dimanche 9 septembre 2007 à 09:16, par Nicolas
2. Le jeudi 20 septembre 2007 à 10:35, par BooK
3. Le vendredi 21 septembre 2007 à 09:17, par Pierrick
Ajouter un commentaire
Les commentaires pour ce billet sont fermés.