Creating more than one user while provisioning azure linux vm via CLI

风格不统一 提交于 2019-12-24 23:20:15

问题


I'm trying to create a linux virtual machine on azure via terraform and my requirement is to setup multiple user accounts on OS. I'm relatively new to Azure Cloud and went through some basic documentation but couldn't find what i was looking for.

I want to automate the process either via terraform or shell scripting by taking advantage of azure-cli. If anybody has anything relevant to my use case or point me towards direction for any alternative way to achieve this task then that would be much appreciated.

Thanks,


回答1:


To create more than one user in the provisioning time of the VM in Azure, you can use the cloud-init file to achieve that. Add the user in the cloud-init file like this:

#cloud-config
users:
  - default
  - name: user1
    groups: sudo
    shell: /bin/bash
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    ssh-authorized-keys:
      - ssh-rsa AAAAB3<snip>
  - name: user2

For more details about the settings of the user, see Users and Groups in Cloud-init.

The create the VM through the Azure CLI:

az vm create \
  --resource-group myResourceGroup \
  --name centos74 \
  --image OpenLogic:CentOS:7-CI:latest \
  --custom-data cloud_init_add_user.txt \
  --generate-ssh-keys

And the result of the test on my side here:

More details about the steps, see Use cloud-init to add a user to a Linux VM in Azure. I suggest you can do this in the Azure Cloud Shell.



来源:https://stackoverflow.com/questions/55318189/creating-more-than-one-user-while-provisioning-azure-linux-vm-via-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!