Getting 'Host key verification failed' when accessing azure node in CloudShell

Villanueva Gomez, Maria E 40 Reputation points
2023-08-28T21:23:48.2566667+00:00

After provisioning VM in Azure and getting proper pem key for given vm, I want to ssh into vm via CloudShell by using commandL

ssh -i vm-cms-brazil-south-1_key.pem azureuser@191.238.131.50

This feature was working OK previously, but starting few days back I started getting error: Host key verification failed. and I'm not able to ssh into vm anymore.

Any suggestions? Has this access been restricted now?

Azure Cloud Services
Azure Cloud Services
An Azure platform as a service offer that is used to deploy web and cloud applications.
738 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Lehel Salat 0 Reputation points
    2023-08-29T18:17:22.9133333+00:00

    How to Address SSH Host Key Verification Issues in Cloud Shell (temporary)

    Why is Host Key Verification Important? Host key verification ensures the authenticity of the server you are connecting to. It protects against Man-in-the-Middle (MitM) attacks. Ignoring or bypassing this verification can expose sensitive data and compromise the security of your server.

    Option 1: Manual Verification

    1. Delete the problematic server entry from the known_hosts file in your cloud shell.
    2. Try to log in to the server again. If it does not prompt for host key verification, proceed to the next step.
    3. Log in to your server using a Windows terminal or Linux terminal (not the cloud shell).
    4. Obtain a copy of the server's host key fingerprint using:
    ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub
    
    1. Copy the displayed fingerprint and paste it into your known_hosts file in the cloud shell:
    nano .ssh/known_hosts
    
    
    1. Try logging in again; it should work.

    Option 2: Temporarily Bypass Verification (Not recommended!)

    1. In your cloud shell, navigate to the .ssh directory:
    cd .ssh/
    
    
    1. Create or edit the config file using a text editor like vim:
    vim config or nano config
    
    
    1. Add the following lines to disable host key checking:
    Host *   
       StrictHostKeyChecking no
    
    1. After logging in and verifying the server's host key, delete the config file or comment out the lines you added:
    #Host *   
     #StrictHostKeyChecking no
    

    Warning: Disabling StrictHostKeyChecking is risky and not recommended for regular use. Always ensure you are connecting to the intended server.


  2. Amandeep Singh Monga 0 Reputation points
    2023-09-01T08:54:27.61+00:00

    The solution doesn't work for me, since I don't see known hosts file generated.

    amandeep [ ~/.ssh ]$ ls -altr

    total 16

    drwxr-xr-x 4 amandeep amandeep 4096 Sep 1 08:46 ..

    -rw-r--r-- 1 amandeep amandeep 591 Sep 1 08:46 id_rsa.pub

    -r-------- 1 amandeep amandeep 2635 Sep 1 08:46 id_rsa

    drwx------ 2 amandeep amandeep 4096 Sep 1 08:46 .

    amandeep [ ~/.ssh ]$

    I re-generated the key but the problem is same.

    amandeep [ ~ ]$ ssh -i aman-first-vm_key.pem azureuser@20.125.120.47

    Host key verification failed.

    amandeep [ ~ ]$ ssh-keygen -t rsa

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.