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,
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.