你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Export-AzSshConfig
此 cmdlet 导出一个 SSH 配置文件,该文件可用于通过支持 OpenSSH 配置和证书的客户端应用程序连接到 Azure 资源。 可以使用 Microsoft Entra ID 颁发的证书或本地用户凭据创建 SSH 配置文件。
语法
Export-AzSshConfig
-ResourceGroupName <String>
-Name <String>
-ConfigFilePath <String>
[-PublicKeyFile <String>]
[-PrivateKeyFile <String>]
[-UsePrivateIp]
[-LocalUser <String>]
[-Port <String>]
[-ResourceType <String>]
[-CertificateFile <String>]
[-Overwrite]
[-KeysDestinationFolder <String>]
[-Force]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Export-AzSshConfig
-Ip <String>
-ConfigFilePath <String>
[-PublicKeyFile <String>]
[-PrivateKeyFile <String>]
[-LocalUser <String>]
[-Port <String>]
[-CertificateFile <String>]
[-Overwrite]
[-KeysDestinationFolder <String>]
[-Force]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Export-AzSshConfig
-ResourceId <String>
-ConfigFilePath <String>
[-PublicKeyFile <String>]
[-PrivateKeyFile <String>]
[-UsePrivateIp]
[-LocalUser <String>]
[-Port <String>]
[-CertificateFile <String>]
[-Overwrite]
[-KeysDestinationFolder <String>]
[-Force]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
说明
导出的 SSH 配置文件可用于通过支持 OpenSSH 配置和证书的客户端应用程序连接到 Azure 资源。 git 和 rsync 等应用程序可以通过将命令设置为“ssh -F /path/to/config”来使用配置文件。 例如:rsync -e“ssh -F /path/to/config”。 用户可以创建使用 Microsoft Entra ID 颁发的证书或本地用户凭据的 ssh 配置文件。 重要说明:连接到 Azure Arc 资源时,此 cmdlet 需要同时在客户端计算机中安装 Az.Ssh.ArcProxy 模块。 该 cmdlet 将尝试从 PowerShell 库安装模块,但用户还可以选择自行安装该模块。 用户还必须有权在 Az.Ssh.ArcProxy 模块中执行代理文件,否则连接将失败。 可以在 PowerShell 库中找到 Az.Ssh.ArcServer 模块:https://aka.ms/PowerShellGallery-Az.Ssh.ArcProxy。
示例
示例 1:导出 SSH 配置文件,以便使用 Microsoft Entra ID 颁发的证书进行身份验证连接到资源。
Export-AzSshConfig -ResourceGroupName myRg -Name myMachine -ConfigFilePath ./sshconfig.config
如果未提供 -LocalUser,cmdlet 将尝试创建证书以使用 Microsoft Entra ID 登录。 目前仅支持运行 Linux OS 的资源。 使用 Microsoft Entra ID 登录到资源时,配置条目中的主机名将为 Azure VM 的“{资源组名称}-{资源名称}”或“{ip address}”。
示例 2:导出 SSH 配置文件,以便使用 Microsoft Entra ID 颁发的证书连接到 Azure 虚拟机的公共 IP。
Export-AzSshConfig -Ip 1.2.3.4 -ConfigFilePath ./sshconfig.config
示例 3:使用 SSH 证书导出 SSH 配置文件以使用 SSH 证书连接到 Azure 资源上的本地用户进行身份验证
Export-AzSshConfig -ResourceGroupName myRg -Name myVm -LocalUser azureuser -CertificateFile ./cert -PrivateKeyFile ./id_rsa -ConfigFilePath ./sshconfig.config
使用本地用户凭据登录时,配置条目中的主机名将为 Azure VM 的“{资源组名称}-{resource name}-{username}”或“{ip address}-{username}”。
示例 4:使用 SSH 私钥导出 SSH 配置文件以使用 SSH 私钥连接到 Azure 资源上的本地用户进行身份验证
Export-AzSshConfig -ResourceGroupName myRg -Name myVm -LocalUser azureuser -PrivateKeyFile ./id_rsa -ConfigFilePath ./sshconfig.config
示例 5:使用交互式用户名和密码导出 SSH 配置文件以使用交互式用户名和密码连接到 Azure 资源上的本地用户进行身份验证
Export-AzSshConfig -ResourceGroupName myRg -Name myVm -LocalUser azureuser -ConfigFilePath ./sshconfig.config
示例 6:确定证书的生成密钥和证书的存储位置。
Export-AzSshConfig -ResourceGroupName myRg -Name myVm -KeysDestinationFolder /home/user/mykeys -ConfigFilePath ./sshconfig.config
默认情况下,生成的密钥和证书存储在配置文件所在的同一目录中的“az_ssh_config”目录中。 -KeysDestinationFolder 参数允许用户确定密钥的存储位置。
示例 7:创建用于任何 Azure VM 的通用配置。
Export-AzSshConfig -Ip * -ConfigFilePath ./sshconfig.config
示例 8:提供目标的资源类型。
Export-AzSshConfig -ResourceGroupName myRg -Name myVm -ResourceType Microsoft.Compute/virtualMachines -ConfigFilePath ./sshconfig.config
当资源组中有多个受支持的资源具有相同名称时,此参数非常有用。
参数
-CertificateFile
用于向本地用户帐户进行身份验证的 SSH 证书。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-ConfigFilePath
要向其写入 SSH 配置的路径。
类型: | String |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | False |
接受通配符: | False |
-DefaultProfile
用于与 Azure 通信的凭据、帐户、租户和订阅。
类型: | IAzureContextContainer |
别名: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Force
连接到 Arc 资源时,在更新连接终结点中允许的 SSH 连接的端口以匹配目标端口或根据需要从 PowerShell 库安装 Az.Ssh.ArcProxy 模块之前,请不要提示进行确认。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Ip
目标 Azure VM 的 IP 地址。
类型: | String |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | False |
接受通配符: | False |
-KeysDestinationFolder
将存储生成的密钥和证书的目录。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-LocalUser
目标资源中本地用户的用户名。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Name
目标 Azure 资源的名称。
类型: | String |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-Overwrite
覆盖配置文件,而不是将新条目追加到文件末尾。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Port
要连接到远程主机上的端口。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-PrivateKeyFile
私钥文件的路径。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-PublicKeyFile
公钥文件的路径。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-ResourceGroupName
资源组名称。
类型: | String |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-ResourceId
目标资源的资源 ID。
类型: | String |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-ResourceType
目标资源的资源类型。
类型: | String |
接受的值: | Microsoft.HybridCompute/machines, Microsoft.Compute/virtualMachines, Microsoft.ConnectedVMwarevSphere/virtualMachines, Microsoft.ScVmm/virtualMachines, Microsoft.AzureStackHCI/virtualMachines |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-UsePrivateIp
连接到 Azure VM 时,此标志指定应连接到 VM 的其中一个专用 IP。 它需要连接到专用 IP。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |