Passwordless scp with Python and pexpect

I have to deal with a lot of Unix/Linux/BSD boxes at work. The problem with such large number of boxes is copying my config files and .ssh directory first time I use them. Many a times, for some new work, I need to configure multiple boxes. It's quite a pain to enter passwords and pass-phrases that many times.

So, I decided to automate this copying with python and pexpect.



The script is really simple. You invoke it as follows:


$ pyscp.py -s .ssh,.vimrc,.zshrc,.screenrc,.inputrc -t node1,node2,node3



It will copy .vimrc, .zshrc .. to mentioned nodes. The automation looks for prompts asking for passphrases or passwords. You just have to enter your passwords once. On all subsequent attempts, the cached passwords is reused.

Password-less access can be configured using ssh-agents as well but this approach is generalized for all the cases - ssh not configured for public key authentication, ssh configured for keys with/without passphrase, with/without agent.The code can be cleaned further and made more elegant but it does the job.