Adding a new ssh key to the azure linux vm
To add a new SSH key to an Azure Linux VM, you can follow these steps:
Method 1: Using the Azure CLI
- Install the Azure CLI on your machine if you haven't already.
- Connect to your Azure subscription using the Azure CLI:
az login
- Get the resource ID of your Linux VM:
az vm show --name <vm-name> --resource-group <resource-group-name> --query id --output tsv
- Use the
az vm openssh
command to add a new SSH key to the VM:az vm openssh --resource-id <resource-id> --ssh-key-name <ssh-key-name> --ssh-key-value <ssh-key-value>
Replace
<resource-id>
with the resource ID of your VM,<ssh-key-name>
with a name for the new SSH key, and<ssh-key-value>
with the contents of the new SSH key.
Method 2: Using the Azure Portal
- Log in to the Azure Portal: https://portal.azure.com/
- Navigate to your Linux VM and click on "Networking" in the left-hand menu.
- Click on "SSH public key" under "Settings".
- Click on "Add SSH public key" and enter a name for the new SSH key.
- Paste the contents of the new SSH key into the "Public key" field.
- Click "Save" to add the new SSH key to the VM.
Method 3: Using SSH
- Connect to your Linux VM using SSH:
ssh user@<vm-public-ip>
- Add the new SSH key to the VM using the
ssh-add
command:ssh-add -a <ssh-key-file>
Replace
<ssh-key-file>
with the path to the new SSH key file.
Verify the new SSH key
After adding the new SSH key, you can verify that it has been added successfully by running the following command on the VM:
cat ~/.ssh/authorized_keys
This should display the contents of the authorized_keys
file, which should include the new SSH key.
That's it! Your new SSH key should now be added to your Azure Linux VM.