Edit

Share via


Add-AzVMSshPublicKey

Adds the public keys for SSH for a virtual machine, when only creating the VM.

Syntax

Default (Default)

Add-AzVMSshPublicKey
    [-VM] <PSVirtualMachine>
    [[-KeyData] <String>]
    [[-Path] <String>]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

Description

The Add-AzVMSshPublicKey cmdlet adds the public keys that you can use to connect to a Linux virtual machine over Secure Shell (SSH). This cannot be used after VM creation, if you try to use this after VM creation without Update-AzVM, there will be no error, if you use the command with Update-AzVM, the command will error.

Examples

Example 1: Add a public key to a virtual machine

$VirtualMachine = Get-AzVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07"
$VirtualMachine = Add-AzVMSshPublicKey -VM $VirtualMachine -KeyData "MIIDszCCApugAwIBAgIJALBV9YJCF/tAMA0GCSq12Ib3DQEB21QUAMEUxCzAJBgNV" -Path "/home/admin/.ssh/authorized_keys"

The first command gets the virtual machine named VirtualMachine07 by using the Get-AzVM cmdlet. The command stores the virtual machine in the $VirtualMachine variable. The second command adds the public key to the location on VirtualMachine07 that the Path parameter specifies.

Parameters

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure.

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzContext, AzureRmContext, AzureCredential

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-KeyData

Specifies a base 64 encoding of a public key. You can connect to a Linux virtual machine by using SSH or by using the key that this parameter specifies.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:1
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Path

Specifies the full path of a file, on the virtual machine, where this cmdlet stores the SSH public key. If the file already exists, this cmdlet appends the key to the file.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:2
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-VM

Specifies the virtual machine object that this cmdlet modifies. To obtain a virtual machine object, use the Get-AzVM cmdlet. You can use the New-AzVMConfig cmdlet to create a virtual machine object.

Parameter properties

Type:PSVirtualMachine
Default value:None
Supports wildcards:False
DontShow:False
Aliases:VMProfile

Parameter sets

(All)
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:True
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

PSVirtualMachine

String

Outputs

PSVirtualMachine