无法顺利切入Azure Linux虚拟机

时间:2020-11-04 01:30:07

标签: azure virtual-machine azure-virtual-machine

我遵循以下指南来使用Terraform设置Linux虚拟机:

https://docs.microsoft.com/en-us/azure/developer/terraform/create-linux-virtual-machine-with-infrastructure

所有内容均已在Azure中成功创建。我无法进入ssh虚拟机的最后一步。我在Windows powershell中使用以下命令:

ssh azureuser @ public_ip_here

它给了我以下错误:

Object [] arObj = new double [][][] {{{1.1, 1.2, 1.3}, {2.1, 2.2, 2.3}} };

我尝试通过下载RDP文件并将其导入RDP来从Azure门户中使用RDP文件,但是出现以下错误:

Doesn't work with RDP either

我尝试过的事情:

  1. 使用上述常规ssh命令
  2. 尝试将私钥放入.pem文件并为其分配受限权限。然后使用ssh -i命令传递此密钥。这也不起作用
  3. 使用从Azure门户下载的RDP文件(如下所示的错误)
  4. 在Azure门户中运行虚拟机的测试连接功能,它显示连接成功,但是我仍然无法访问VM。

我想知道是否必须以某种方式配置Azure门户以使自己能够在VM中进行ssh。

我的main.tf代码是:

azureuser@52.186.144.190: Permission denied (publickey).

任何帮助/指针将不胜感激!

2 个答案:

答案 0 :(得分:1)

我的验证之后,您可以将输出的私人Pem密钥保存到主目录中名为key.pem的文件中。例如,在Windows 10中为C:\Users\username\,在Linux中为/home/username/

enter image description here

然后,您可以通过外壳程序中的命令访问Azure VM。

ssh -i "C:\Users\username\key.pem"  azureuser@23.x.x.x

结果

enter image description here

此外,由tls_private_key生成的私钥将不加密地存储在Terraform状态文件中。建议在Terraform外部生成一个私钥文件,并将其安全分发到将运行Terraform的系统中。

您可以在Windows 10的PowerShell中使用ssh-keygen在客户端计算机上创建密钥对。密钥对保存到目录C:\Users\username\.ssh中。

例如,然后您可以使用Terraform函数文件将公钥发送到Azure VM:

admin_ssh_key {
    username       = "azureuser"
    public_key     = file("C:\\Users\\someusername\\.ssh\\id_rsa.pub")     
    #tls_private_key.example_ssh.public_key_openssh
}

答案 1 :(得分:0)

  • 首先创建密钥。

    ssh-keygen -t rsa -b 2048 -C email@example.com

  • 第二步添加key的路径。

    admin_ssh_key {

    import React, { useEffect, useRef } from 'react';
    import { AppState } from 'react-native';
    
    export default function App(){
        const appState = useRef(AppState.currentState);
    
        useEffect(()=>{
            fetch()//here I send post request to update users state to active
            
            AppState.addEventListener("change", handleAppStateChange);
    
            return ()=>{
                AppState.removeEventListener("change", handleAppStateChange);
            }
        },[])
    
        const handleAppStateChange = (nextAppState) =>{
           if(appState.current.match(/inactive|background/) && nextAppState === "active"){
               fetch()// update users status to inactive
           }
           else{
               fetch()// update users status to active
           }
           appState.current = nextAppState;
    
        }
    }
    

    }

  • 终于登录了。

    ssh -i "C:\Users\someusername.ssh\id_rsa" azureuser@20.x.x.x

相关问题