1

I am trying to execute a script on a remote computer. Lets call this (Secondary), the script is as follows, for simplicity porposes,

#!/bin/bash

echo "This is the Remote Machine (Secondary)" > /tmp/test.txt
echo "---------------------------------------------------" >> /tmp/test.txt
echo "Test.sh scandir = $scandir" >> /tmp/test.txt
echo "Test.sh tmpdir = $tmpdir" >> /tmp/test.txt
echo "Test.sh CurrentDir = $CurrentDir" >> /tmp/test.txt
echo "---------------------------------------------------" >> /tmp/test.txt

I can execute the remotely from the primary machine with the following command.

ssh <username>@192.168.1.20 'screen -S TestProcess -d -m ./test.sh'

and the script runs as expected.

However when the script is executed automatically from a system process i get the following error.

Feb 21 06:20:23 Primary test.sh: Host key verification failed.#015

I have generated ssh keys and copied them.

ssh-keygen -R 192.168.1.20
ssh-copy-id <username>@192.168.1.20

What can be the problem?

0

Note that this is about the host key, i.e. the way your client knows that it's contacting the right server. This is unrelated to the key generated by ssh-keygen which lets the server authenticate the user.

“Host key verification failed” indicates that the client had previously recorded the host's public key, but the public key has changed since the last time. This can be due to an attack, to a server reinstallation or to a server IP address or hostname change. The saved host keys are stored per account, which would explain why it works from your account but not from a “system process” (presumably running as a different user). To fix this, run ssh-keygen -R 192.168.1.20 as the user running that system process. Then record the current host key by running ssh username@192.168.1.20 true once as that system user and entering “yes” when prompted.

It's also possible that you've enabled the option StrictHostKeyChecking, or that ssh is unable to prompt you to confirm the host key verification the first time and failing because of that. There would be another message indicating this before “Host key verification failed”. Either way, as before, record the current host key by running ssh username@192.168.1.20 true once as that system user and entering “yes” when prompted. The key will be stored in the file .ssh/known_hosts under the user's home directory.

  • Something has to be wrong here. I have already done these procedures with no success. I checked /etc/ssh/ssh_config and StrictHostkeyChecking is not enabled. Since that did not work I went ahead and delete the ~/.ssh directory and the /etc/ssh/ssh_hosts files from both servers. re-ran sudo dpkg-reconfigure openssh-server to generated server keys. then ssh-keygen -t rsa -b 4096 -C "For 192.168.1.20" -f id_20_rsa and ssh-copy-id -i id_20_rsa user2@192.168.1.20 -- I am thinking this is a total reset, and still get the same error. – user68650 Feb 22 '15 at 0:15
  • @user68650 None of this is relevant except deleting the .ssh directory, and that would only be pertinent on the client (not on the server), in the account under which the task calling ssh runs. Furthermore, you should not regenerate the server key, that can only make your life more complicated because you then need to wipe the saved public key in .ssh/known_hosts on the client. Now, delete .ssh/known_hosts on the system account on the client, run ssh username@192.168.1.20 true once as the system account, and don't touch anything else. – Gilles Feb 22 '15 at 0:43
  • Previously tried that as well. Currently there is no ~/.ssh/known_file -- ssh username@192.168.1.20 true - reports "Host key verification failed". – user68650 Feb 22 '15 at 2:13
  • BTW - thank you for the assistance Gilles! Much appreciated. – user68650 Feb 22 '15 at 2:29
  • Think I figured this out. The keys were set correctly from the beginning. The issue was, the automatic script was being lauch the user root. no key for that user existed. I had to copy the keys generated from the correct user over to the root user. this link set me on the track askubuntu.com/questions/497895/… - although PermitRootLogin yes did not work for me. – user68650 Feb 22 '15 at 23:55
0

Think i figure this out. checking the logs for ssh for the automated script revealed

Feb 22 23:46:02 PiScanner scan.sh: debug1: Connecting to 192.168.1.20 [192.168.1.20] port 22.#015
Feb 22 23:46:02 PiScanner scan.sh: debug1: Connection established.#015
Feb 22 23:46:02 PiScanner scan.sh: debug1: permanently_set_uid: 0/0#015
Feb 22 23:46:02 PiScanner scan.sh: debug1: identity file /root/.ssh/id_rsa type 1#015
Feb 22 23:46:02 PiScanner scan.sh: debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048#015
Feb 22 23:46:02 PiScanner scan.sh: debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048#015
Feb 22 23:46:02 PiScanner scan.sh: debug1: **identity file /root/.ssh/id_rsa-cert type -1#015**
Feb 22 23:46:02 PiScanner scan.sh: debug1: identity file /root/.ssh/id_dsa type -1#015
Feb 22 23:46:02 PiScanner scan.sh: debug1: identity file /root/.ssh/id_dsa-cert type -1#015
Feb 22 23:46:02 PiScanner scan.sh: debug1: identity file /root/.ssh/id_ecdsa type -1#015
Feb 22 23:46:02 PiScanner scan.sh: debug1: identity file /root/.ssh/id_ecdsa-cert type -1#015
Feb 22 23:46:02 PiScanner scan.sh: debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2#015
Feb 22 23:46:02 PiScanner scan.sh: debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH*#015

The log for the user i generated the keys had

    debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
    debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/pi/.ssh/id_rsa-cert type -1
    debug1: identity file /home/pi/.ssh/id_dsa type -1
    debug1: identity file /home/pi/.ssh/id_dsa-cert type -1
    debug1: identity file /home/pi/.ssh/id_ecdsa type -1
    debug1: identity file /home/pi/.ssh/id_ecdsa-cert type -1
    debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2

I had the copy the keys generated over the to root user. ~/.ssh directory after a did a sudo -i

https://askubuntu.com/questions/497895/permission-denied-for-rootlocalhost-for-ssh-connection

PermitRootLogin yes in the ssh_config file did not work me and did generate other errord.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.