通过 R 使用 Linux Azure DSVM 进行 SSH public 密钥身份验证

SSH public key authentication with Linux Azure DSVM through R

我正在尝试使用 R AzureDSVM 包通过 R 创建 Linux DSVM。我正在阅读指南 https://raw.githubusercontent.com/Azure/AzureDSVM/master/vignettes/10Deploy.Rmd(Azure DSVM 指南)

首先,指南要求您创建一个 Azure Active Directory 应用程序,它将提供 "tenant ID"、"client ID" 和 "user key",http://htmlpreview.github.io/?https://github.com/Microsoft/AzureSMR/blob/master/inst/doc/Authentication.html(Azure SMR)中描述的指南授权指南)

据我了解,这会创建一个在 Azure Active Directory 中注册的应用程序,为该应用程序创建一个 "authentication key",这是用户密钥,并将该应用程序与资源组相关联。我已经成功完成了。

然后,Azure DSVM 指南以类似于以下的方式创建具有 public 密钥身份验证的 VM:

library(AzureSMR) 
library(AzureDSVM)   

TID <- "123abc"          # Tenant ID
CID <- "456def"          # Client ID
KEY <- "789ghi"          # User key

context <- createAzureContext(tenantID=TID, clientID=CID, authKey=KEY)

resourceGroup<-"myResouceGroup"
location<-"myAzureLocation"
vmUsername<-"myVmUsername"
size<-"Standard_D1_v2"
mrsVmPassword<-"myVmPassword"
hostname<-"myVmHostname"

ldsvm <- deployDSVM(context, 
                    resource.group = resourceGroup,
                    location       = location,
                    hostname       = hostname,
                    username       = vmUsername,
                    size           = size,
                    os = "Ubuntu",
                    pubkey         = PUBKEY)

该指南模糊地描述了从用户私钥创建一个 public 密钥 (PUBKEY),该密钥被发送到 VM 以允许它提供 SSH 身份验证:

To get started we need to load our Azure credentials as well as the user’s ssh public key. Public keys on Linux are typically created on the users desktop/laptop machine and will be found within ~/.ssh/id_rsa.pub. It will be convenient to create a credentials file to contain this information. The contents of the credentials file will be something like the foloowing and we assume the user creates such a file in the current working directory, naming the file _credentials.R. Replace with the user’s username.

TID <- "72f9....db47"          # Tenant ID
CID <- "9c52....074a"          # Client ID
KEY <- "9Efb....4nwV....ASa8=" # User key

PUBKEY   <- readLines("~/.ssh/id_rsa.pub") # For Linux DSVM

我的问题:

这个public密钥PUBKEY是从Azure SMR Auth指南中设置Azure Active Directory应用程序创建的authentication/user密钥生成的吗(上述脚本中的KEY变量)?如果是这样,如何?我尝试使用 R sodium 库 pubkey(charToRaw(KEY)) 来执行此操作,但我得到 "Invalid key, must be exactly 32 bytes".

如果 PUBKEY 不是从 KEY 生成的,它是从什么生成的?包如何知道如何使用此 public 密钥的私钥进行身份验证?

AAD 密钥用于对 AAD 进行身份验证。 public/private 密钥对是独立的,用于对 VM 进行身份验证。如果您没有 public 密钥(在文件 ~/.ssh/id_rsa.pub 中),您可以使用 Linux 上的 ssh-keygen 创建一个。

默认情况下,SSH 连接使用私钥(在 ~/.ssh/id_rsa 中)。

除了 Paul Shealy 的(正确)回答之外还有几件事:

ssh-keygen 也与 ssh、scp 和 curl 一起安装在最新版本的 Windows 10 Pro 上。否则,您可能安装了 Putty ssh 客户端,在这种情况下,您可以使用 puttygen 来保存 public/private 密钥对。

AzureDSVM 相当陈旧并且依赖于不再主动维护的 AzureSMR。如果要部署 DSVM,我建议使用 AzureVM 包,它位于 CRAN and GitHub. This in turn builds on the AzureRMR 包中,它提供了管理 Azure 资源的通用框架。

library(AzureVM)
az <- AzureRMR::az_rm$new(tenant="youraadtenant", app="yourapp_id", password="password")
sub <- az$get_subscription("subscription_id")
rg <- sub$get_resource_group("rgname")

vm <- rg$create_vm(os="Ubuntu",
    username="yourname",
    passkey=readLines("~/.ssh/id_rsa.pub"),
    userauth_type="key")

查看 AzureRMR and AzureVM 小插图了解更多信息。

免责声明:我是 AzureRMR 和 AzureVM 的作者。