I'm migrating some home folders from one Linux box to another using scp. I've saved my public key into the destination box's authorized_keys file and the following command works perfectly when I type it at the command line:
scp myArch.tar root@myOtherServer:/root/dumps
... however when I put this into a script like so...
#!/bin/bash
tar -cf /tmp/$1.tar $1; wait
scp /tmp/$1.tar root@myOtherServer:/root/dumps
.. and call it by passing a folder name as a parameter, I get the following error.
[root@myHost home]# /root/migrate myHomeFolder
Permission denied (publickey).
lost connection
Any ideas what could be the problem?