You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Removing the reference to sensible-editor, given that's not installed in all Linux distros and the sentence is already mentioning they can use the text editor of their preference. Removing also the centos7 and URN image from the sample entry for the vm create to make it Linux agnostic (they could use any image with Cloud-init), changing the last block code from bash to output
Copy file name to clipboardExpand all lines: articles/virtual-machines/linux/cloudinit-add-user.md
+14-11Lines changed: 14 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ author: mattmcinnes
5
5
ms.service: virtual-machines
6
6
ms.collection: linux
7
7
ms.topic: how-to
8
-
ms.date: 05/11/2021
8
+
ms.date: 03/29/2022
9
9
ms.author: mattmcinnes
10
10
ms.subservice: cloud-init
11
11
---
@@ -18,7 +18,7 @@ This article shows you how to use [cloud-init](https://cloudinit.readthedocs.io)
18
18
## Add a user to a VM with cloud-init
19
19
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.
20
20
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.
22
22
23
23
```yaml
24
24
#cloud-config
@@ -32,40 +32,42 @@ users:
32
32
- ssh-rsa AAAAB3<snip>
33
33
```
34
34
> [!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.
36
36
37
37
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.
38
38
39
-
```azurecli-interactive
39
+
```azurecli-interactive
40
40
az group create --name myResourceGroup --location eastus
41
41
```
42
42
43
43
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:
44
44
45
-
```azurecli-interactive
45
+
```azurecli-interactive
46
46
az vm create \
47
47
--resource-group myResourceGroup \
48
-
--name centos74 \
49
-
--image OpenLogic:CentOS:7-CI:latest \
48
+
--name vmName \
49
+
--image imageCIURN \
50
50
--custom-data cloud_init_add_user.txt \
51
51
--generate-ssh-keys
52
52
```
53
+
> [!NOTE]
54
+
> Replace **myResourceGroup**, **vmName**, and **imageCIURN** values accordingly. Make sure an image with Cloud-init is chosen.
53
55
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:
55
57
56
58
```bash
57
-
ssh <publicIpAddress>
59
+
ssh <user>@<publicIpAddress>
58
60
```
59
61
60
62
To confirm your user was added to the VM and the specified groups, view the contents of the */etc/group* file as follows:
61
63
62
64
```bash
63
-
cat /etc/group
65
+
sudo cat /etc/group
64
66
```
65
67
66
68
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:
67
69
68
-
```bash
70
+
```output
69
71
root:x:0:
70
72
<snip />
71
73
sudo:x:27:myadminuser
@@ -74,6 +76,7 @@ myadminuser:x:1000:
74
76
```
75
77
76
78
## Next steps
79
+
77
80
For additional cloud-init examples of configuration changes, see the following:
78
81
79
82
- [Add an additional Linux user to a VM](cloudinit-add-user.md)
0 commit comments