Score:0

Can logint to remote server via SSH but cannot copy file via scp: Host key verification failed

vn flag

So I have set up with 3 VM running Ubuntu 20.04 server. What I am trying to do is copy a folder from machine 1 to machine 2 and then another folder from machine 1 to machine 3.

  1. All machines have OpenSSH installed with the same sshd_config (custom port, password-only etc.)
  2. On the command line I am able to login to any of machines 2 or 3 via the command ssh -p XXX [email protected]. Of course, it asks for the user password, but I can log in.
  3. I have setup a cron to execute following command: sshpass -p 'PASSWORD' scp -r -P PORT# /home/user/folder/ [email protected]:/home/user

When executing for machine 2 everything is OK and the folder and its content is being copied. But when executing for machine 3 I get Host key verification failed which is odd, as I've done the same steps for each machine.

Any help is appreciated.

P.S.: Both on machine 2 and 3, there is an indentical record in /home/user/.ssh/authorized_keys

hr flag
Whose account is the cron job run under? is it `root` or `user`?
vn flag
I'm running both cron as root because the folder I want to copy is under /root folder. But the 'target' user is not root.
hr flag
Right - but it will determine whose home directory it looks in for the `known_hosts` file
vn flag
But then, why I have success copying on machine 2 and get an error when copying on machine 3?
hr flag
I don't know - perhaps you previously logged in to machine 2 from root and accepted its fingerprint?
vn flag
Root login over ssh is forbidden in the sshd_config file. Moreover, just tried to copy a folder as a normal user (via cron again) and again get the same error.
hr flag
Sorry, I'm not talking about root login over ssh - I'm talking about *being root* (or more specifically, having `$HOME` equal to `/root`) when connecting as `[email protected]`. Regardless, you could consider setting `StrictHostKeyChecking` more permissively to avoid the error.
Score:0
vn flag

Just remembered something. I've tried rsync as root from machine 1 to copy over machine 2 and it worked. And thenn I confirmed that cron also works.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.