Using SSH, SCP and RSYNC without a password

Using SSH, SCP and RSYNC without a password

Using SSH, SCP and RSYNC without a password 150 150 Roderick Derks

From time to time you want to write scripts that will allow you to copy files to or execute commands on remote systems. You want to execute these scripts without being prompted for a password and you don't want to store the password in the script file. To achieve this we can use ssh encryption keys.

Configure client:

Log in as root (you can use another user though): 

# cd ~
# ssh-keygen -t dsa
don't add a password

# scp .ssh/id_dsa.pub root@server:/root/

Log in on the server

If nescessary:
# mkdir .ssh
# chmod 700 .ssh

Then continue:
# cat id_dsa.pub >> .ssh/authorized_keys
# rm -f ~/id_dsa.pub

Log in to the client again.  Use rsync to sync a directory. This copies all file in the tmp dir to the tmp dir on the remote host:
# rsync -avu –delete -e ssh /tmp/ root@server:/tmp

-a archive
-u overwrite newer files on the server
-v verbose
-z compressed sending of the files, handy when you have a slow connection like an analoge phone line.
— delete delete files on the receiving host that don't exist on the client side.

Roderick Derks

Liefhebber van fietsen, van het oplossen van IT puzzels, en van het delen van informatie om anderen te helpen.

All stories by:Roderick Derks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Your Name (required)

Your Email (required)

Subject

Your Message

Your Name (required)

Your Email (required)

Subject

Your Message