简体   繁体   English

Trying to Update ssh key to existing user in azure linux vm whcih has been created using SSH Key Service via Azure portal

[英]Trying to Update ssh key to existing user in azure linux vm whcih has been created using SSH Key Service via Azure portal

I am trying to use Add-AzVMSshPublicKey cmdlet to update ssh key on existing Azure linux VM, command executed without an issue but key hasnt been updated on server.我正在尝试使用 Add-AzVMSshPublicKey cmdlet 更新现有 Azure linux VM 上的 ssh 密钥,命令已在服务器上执行但未更新密钥。 Is there any other way available where i can able to achieve OR any Azure cli command to do same?有没有其他方法可以实现或任何 Azure cli 命令可以做到这一点?

The Add-AzVMSshPublicKey cmdlet is used to add the public keys for SSH for a virtual machine, when only creating the VM . Add-AzVMSshPublicKey cmdlet 用于在仅创建 VM 时为虚拟机添加 SSH 的公钥。 If you use the command with Update-AzVM, the command will error.如果将该命令与 Update-AzVM 一起使用,该命令将出错。 So it does not use to add the keys after VM is created.因此它不用于在创建 VM 后添加密钥。

The following example updates the SSH key for the user azureuser on the VM named myVM .以下示例更新名为myVM的 VM 上用户azureuser的 SSH 密钥。

az vm user update \
  --resource-group myResourceGroup \
  --name myVM \
  --username azureuser \
  --ssh-key-value ~/.ssh/id_rsa.pub

You can use the above CLI commands to append the new public key text to the ~/.ssh/authorized_keys file for the admin user on the VM.您可以使用上述 CLI 命令 append 将新的公钥文本添加到 VM 上管理员用户的~/.ssh/authorized_keys文件中。 This does not replace or remove any existing SSH keys.这不会替换或删除任何现有的 SSH 密钥。 You can SSH into that VM to remove the old public key if you would like to remove it.如果您想删除旧公钥,您可以将 SSH 插入该 VM 以删除旧公钥。

Read Manage administrative users, SSH, and check or repair disks on Linux VMs using the VMAccess Extension with the Azure CLI for more details.阅读管理管理用户 SSH,并使用带有 Azure CLI 的 VMAccess 扩展检查或修复 Linux VM 上的磁盘以了解更多详细信息。

Alternatively, you can reset the SSH key from the Azure portal---> reset password.或者,您可以从 Azure 门户网站重置 SSH 密钥---> 重置密码。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM