Description
Install the administrator’s SSH public key with ssh_public_keys. The ssh_password_enabled setting controls operating-system SSH logins on an Azure Linux VM.
Potential impact
Anyone who can reach SSH and knows the account password can sign in with that account’s permissions.
Remediation
For a new VM, set ssh_password_enabled: false. On an existing VM, verify administrator key access in a separate session before disabling password logins in the guest’s SSH configuration. Protect the private key on the client.
Examples
path points to authorized_keys inside the VM. Pass the public key contents in ssh_public_key and provide the custom image and network required for the deployment.
Before
yaml
- name: Create a Linux VM
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm001
vm_size: Standard_DS1_v2
admin_username: adminUser
admin_password: "{{ vm_admin_password }}"
image: customimage001
os_type: Linux
no_log: true
After
yaml
- name: Create a Linux VM
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm001
vm_size: Standard_DS1_v2
admin_username: adminUser
ssh_password_enabled: false
ssh_public_keys:
- path: /home/adminUser/.ssh/authorized_keys
key_data: "{{ ssh_public_key }}"
image: customimage001
os_type: Linux