Here is a quick how to tip.  Scripting between servers is handy for routine file transfers or backups, but in order to make scripts unattended, you will have to add your server credentials to your script in plain text or setup authentication keys for you server.  The authentication keys are very easy to create, but you must always remember to create your key on the client.  Then, you copy the key to ~/.ssh/authorized_keys on the destination server for the user you will that you specify in your script.  I know that seems backwards, but since the server has the client’s key, it has permission to login without a password.  So, moving on, here is the command to create the key on you client; you will then distribute this key to your servers.

sudo ssh-keygen -t dsa -f /root/.ssh/id_dsa -C "your comment"

Note: your root user home directory might have a different path than I specified above.

Next, you need to add the key to the authorized_keys file on the server; here is an easy method:

sudo cat /root/.ssh/ | ssh root@remote_address 'cat - >> ~/.ssh/authorized_keys'

You should be able to login to the server from the client without using a password now, just make sure you run your command using sudo.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>