I am trying to transfer files from one server to another using the scp command without having to enter a password. To this end I generated key files and copied them to each server's .ssh folder; but when I run the scp command I still need to type the password for my other server.

I am using Cloudways servers; we can't edit .ssh files on those but I added the keys using their portal and they were added to authorized_keys.

I am using this command:

scp -o StrictHostKeyChecking=no -rv /home/00000000.cloudwaysapps.com/fdbbgbgbgb/public_html/Test1/test.html [email protected]:/home/0000000.cloudwaysapps.com/bgbtrbgb/public_html/Test1

What do we need to do to automate transfers between two different servers? I already tried ssh-keygen but it didn't work on the servers. Locally I generated keys and added them to both servers manually, and with those I can log in to both servers without entering a password; I am only asked for a password when transferring files between the servers.

Can anyone explain why this is happening, and how I should configure the SSH keys of my second server on the first one?

  • explain how you are starting the script that fails. Using cron ? As root or a specific user ? Just guessing it's not finding the key-files!
    – X Tian
    Commented Mar 22 at 12:21
  • Yes it is prompting password for second server where i am transferring file
    – Jay
    Commented Mar 22 at 12:23

1 Answer 1


From local i generated keys and added to both servers manually with that i can login in both servers without typing password it is only giving me password while transferring files.

When you copy a file between your local machine and a remote one, or login to it from your local machine, you can set up certificate-based authentication, and indeed you note that this already works. (At least, you explained that you can ssh without needing a password, and this is much the same thing.)

date >date.txt
scp date.txt remoteHostA:
scp date.txt remoteHostB:

However, what you are now doing is copying from remoteHostA to remoteHostB while logged in to remoteHostA. At that point remoteHostA is now the client and you need to treat it as such.

On remoteHostA you need to create ssh keys using something like ssh-keygen -t ed25519 and transfer and install the resulting public key to remoteHostB in much the same way that you did when installing the public key from your local computer.

Alternatively, you can transfer files from remoteHostA to remoteHostB via your local system, but you have to be logged into that and run the command from there for it to work:

scp -3v remoteHostA:date.txt remoteHostB:

(You only need the -r flag if you're copying a directory tree of files.)

  • thank you for your answer our problem is solved. It is giving us password because we did it manually on cloudways server we can't .ssh files. We gone to cloudways support and they added keys from their side after that problem is solved.
    – Jay
    Commented Mar 23 at 9:37
  • @Jay glad to hear the issue is solved. If this answer helped you please ✔ accept it Commented Mar 23 at 14:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .