Lab 001: Create SSH Key Pair for Azure Virtual Machine
Requirements
Create Azure ssh key pair
Note
The solution can be implemented using both the Azure Cloud Console and the Azure CLI. This document outlines the CLI-based approach to accomplish these tasks. It is recommended to first explore the Azure Cloud Console for hands-on experience and a practical understanding of the process before utilizing the CLI approach, unless specifically instructed otherwise.
Prerequisites
- Azure CLI is installed and authenticated on the working host.
- The
~/.sshdirectory is writable for key generation.
Steps
SSH_PRIVATE_KEY="$HOME/.ssh/id_rsa"
SSH_PUBLIC_KEY="$HOME/.ssh/id_rsa.pub"
# Create RSA SSH key pair if missing
if [ ! -f "$SSH_PUBLIC_KEY" ]; then
ssh-keygen -t rsa -b 2048 -f "$SSH_PRIVATE_KEY" -q -N ""
fi
# Display public key for Azure VM usage
cat "$SSH_PUBLIC_KEY"
Verification
- Confirm the public key file exists at
~/.ssh/id_rsa.pub. - Confirm the private key file exists at
~/.ssh/id_rsa. - Confirm the public key content starts with
ssh-rsa.