Azure Compute SSH Public Key
This page shows how to write Terraform and Azure Resource Manager for Compute SSH Public Key and write them securely.
azurerm_ssh_public_key (Terraform)
The SSH Public Key in Compute can be configured in Terraform with the resource name azurerm_ssh_public_key
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_ssh_public_key" "ssh_key" {
name = "terraform_ho02_ssh_key"
resource_group_name = "terraform_ho02"
location = "westeurope"
public_key = file("id_rsa.pub")
}
resource "azurerm_ssh_public_key" "ssh" {
name = var.name
resource_group_name = var.resource_group
location = var.location
public_key = var.key
tags = {
resource "azurerm_ssh_public_key" "ssh_key_HaProxy" {
name = "ssh_key_HaProxy"
resource_group_name = azurerm_resource_group.Ressource_Paris_VM.name
location = var.azure_location_Paris
public_key = "YOUR_OWN_SSH-KEY"
}
resource "azurerm_ssh_public_key" "RedTeam_SSH_jump" {
name = "RedTeam-SSH-jump"
resource_group_name = azurerm_resource_group.RedTeam_RG.name
location = azurerm_resource_group.RedTeam_RG.location
public_key = file("C:/users/aRustyDev.ARUSTY/.ssh/id_rsa.pub")
}
resource "azurerm_ssh_public_key" "example" {
name = "example"
resource_group_name = "example"
location = "West Europe"
public_key = file("~/.ssh/id_rsa.pub")
resource "azurerm_ssh_public_key" "example" {
name = var.name
resource_group_name = var.resource_group
location = var.location
public_key = file(var.public_key)
resource "azurerm_ssh_public_key" "example"{
name = "AZKey"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
public_key = file("key_pub/AZKey.txt")
}
resource "azurerm_ssh_public_key" "ssh" {
name = var.name
resource_group_name = var.resource_group
location = var.location
public_key = var.key
tags = var.tags
resource "azurerm_ssh_public_key" "mysshkey" {
location = var.location
name = var.name
public_key = var.SSH_KEY
resource_group_name = var.rg_name
resource "azurerm_ssh_public_key" "pub_key" {
name = "Key_for_vm"
resource_group_name = azurerm_resource_group.arg.name
location = azurerm_resource_group.arg.location
public_key = file("~/.ssh/id_rsa.pub")
}
Parameters
-
id
optional computed - string -
location
required - string -
name
required - string -
public_key
required - string -
resource_group_name
required - string -
tags
optional - map from string to string -
timeouts
single block
Explanation in Terraform Registry
Manages a SSH Public Key.
Tips: Best Practices for The Other Azure Compute Resources
In addition to the azurerm_linux_virtual_machine, Azure Compute has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_linux_virtual_machine
Ensure to use SSH authentication for virtual machines
It is better to use SSH authentication for virtual machines instead of password authentication to enforce more secure ways.
azurerm_managed_disk
Ensure to enable the encryption on managed disks
It is better to enable the encryption on managed disks.
azurerm_virtual_machine
Ensure to use SSH authentication for virtual machines
It is better to use SSH authentication for virtual machines instead of password authentication to enforce more secure ways.
Microsoft.Compute/SshPublicKeys (Azure Resource Manager)
The SshPublicKeys in Microsoft.Compute can be configured in Azure Resource Manager with the resource name Microsoft.Compute/SshPublicKeys
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sshPublicKeys_name": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sshKeyName": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"virtualMachines_tomerykserver1_name": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sshName": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sshPublicKeys_vm_name": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"registries_proj2_name": {
Frequently asked questions
What is Azure Compute SSH Public Key?
Azure Compute SSH Public Key is a resource for Compute of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Compute SSH Public Key?
For Terraform, the emberiris/terraform-workshop, ahelal/cdf and etienne-plagnieux/Logskills_Terraform_Azure source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the aryamo/azurejson, dohughes-msft/sap and ahelal/cdf source code examples are useful. See the Azure Resource Manager Example section for further details.