Skip to content

Commit 1f5197a

Browse files
authored
Merge pull request #232644 from divargas-msft/patch-1
[Doc-a-thon] Updating cloudinit-add-user
2 parents 5288316 + a6feb64 commit 1f5197a

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

articles/virtual-machines/linux/cloudinit-add-user.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: mattmcinnes
55
ms.service: virtual-machines
66
ms.collection: linux
77
ms.topic: how-to
8-
ms.date: 05/11/2021
8+
ms.date: 03/29/2022
99
ms.author: mattmcinnes
1010
ms.subservice: cloud-init
1111
---
@@ -18,7 +18,7 @@ This article shows you how to use [cloud-init](https://cloudinit.readthedocs.io)
1818
## Add a user to a VM with cloud-init
1919
One of the first tasks on any new Linux VM is to add an additional user for yourself to avoid the use of *root*. SSH keys are best practice for security and usability. Keys are added to the *~/.ssh/authorized_keys* file with this cloud-init script.
2020

21-
To add a user to a Linux VM, create a file in your current shell named *cloud_init_add_user.txt* and paste the following configuration. For this example, create the file in the Cloud Shell not on your local machine. You can use any editor you wish. Enter `sensible-editor cloud_init_add_user.txt` to create the file and see a list of available editors. Choose #1 to use the **nano** editor. Make sure that the whole cloud-init file is copied correctly, especially the first line. You need to provide your own public key (such as the contents of *~/.ssh/id_rsa.pub*) for the value of `ssh-authorized-keys:` - it has been shortened here to simplify the example.
21+
To add a user to a Linux VM, create a file in your current shell named *cloud_init_add_user.txt* and paste the following configuration. For this example, create the file in the Cloud Shell not on your local machine. You can use any editor you wish. Make sure that the whole cloud-init file is copied correctly, especially the first line. You need to provide your own public key (such as the contents of *~/.ssh/id_rsa.pub*) for the value of `ssh-authorized-keys:` - it has been shortened here to simplify the example.
2222

2323
```yaml
2424
#cloud-config
@@ -32,40 +32,42 @@ users:
3232
- ssh-rsa AAAAB3<snip>
3333
```
3434
> [!NOTE]
35-
> The #cloud-config file includes the `- default` parameter included. This will append the user, to the existing admin user created during provisioning. If you create a user without the `- default` parameter - the auto generated admin user created by the Azure platform would be overwritten.
35+
> The #cloud-config file includes the `- default` parameter included. This will append the user, to the existing admin user created during provisioning. If you create a user without the `- default` parameter - the auto generated admin user created by the Azure platform would be overwritten.
3636

3737
Before deploying this image, you need to create a resource group with the [az group create](/cli/azure/group) command. An Azure resource group is a logical container into which Azure resources are deployed and managed. The following example creates a resource group named *myResourceGroup* in the *eastus* location.
3838

39-
```azurecli-interactive
39+
```azurecli-interactive
4040
az group create --name myResourceGroup --location eastus
4141
```
4242

4343
Now, create a VM with [az vm create](/cli/azure/vm) and specify the cloud-init file with `--custom-data cloud_init_add_user.txt` as follows:
4444

45-
```azurecli-interactive
45+
```azurecli-interactive
4646
az vm create \
4747
--resource-group myResourceGroup \
48-
--name centos74 \
49-
--image OpenLogic:CentOS:7-CI:latest \
48+
--name vmName \
49+
--image imageCIURN \
5050
--custom-data cloud_init_add_user.txt \
5151
--generate-ssh-keys
5252
```
53+
> [!NOTE]
54+
> Replace **myResourceGroup**, **vmName**, and **imageCIURN** values accordingly. Make sure an image with Cloud-init is chosen.
5355

54-
SSH to the public IP address of your VM shown in the output from the preceding command. Enter your own **publicIpAddress** as follows:
56+
SSH to the public IP address of your VM shown in the output from the preceding command. Enter your own **user** and **publicIpAddress** as follows:
5557

5658
```bash
57-
ssh <publicIpAddress>
59+
ssh <user>@<publicIpAddress>
5860
```
5961

6062
To confirm your user was added to the VM and the specified groups, view the contents of the */etc/group* file as follows:
6163

6264
```bash
63-
cat /etc/group
65+
sudo cat /etc/group
6466
```
6567

6668
The following example output shows the user from the *cloud_init_add_user.txt* file has been added to the VM and the appropriate group:
6769

68-
```bash
70+
```output
6971
root:x:0:
7072
<snip />
7173
sudo:x:27:myadminuser
@@ -74,6 +76,7 @@ myadminuser:x:1000:
7476
```
7577

7678
## Next steps
79+
7780
For additional cloud-init examples of configuration changes, see the following:
7881

7982
- [Add an additional Linux user to a VM](cloudinit-add-user.md)

0 commit comments

Comments
 (0)