大网数据广告活动
服务器运维问答

How do you SSH in to an Azure VM through an Azure Bastion?

· 52CE 我爱测

My initial understanding was that an Azure Bastion acts like a lightweight SSH (and RDP) gateway to resources -- specifically, VMs -- on the same virtual network, rather than provisioning a full VM as a jumpbox. That is, I would …

问题原文

原帖链接 · Xophmeister · CC BY-SA 4.0

My initial understanding was that an Azure Bastion acts like a lightweight SSH (and RDP) gateway to resources -- specifically, VMs -- on the same virtual network, rather than provisioning a full VM as a jumpbox. That is, I would expect to be able to do this, from anywhere on the public Internet, to SSH into a VM on the same network:

ssh -i /path/to/private.key -J BASTION_IP user@VM_IP

Where BASTION_IP is the public IP associated with the Bastion resource and VM_IP is the internal IP address of the VM in a sibling subnet to the Bastion subnet.

I've set this up in Terraform, using the "Basic" Bastion SKU but, when I try connecting, it times out. In the Azure Poral, there is an option named "Native Client Support" (which needs the "Standard" SKU), exposed as the tunneling_enabled argument in the respective Terraform resource. With those changes made, my connection still times out.

Following the rabbit hole of documentation suggests that you have to use the Azure CLI. Indeed, I can get tunnelling to work using the Azure CLI -- the SSH extension is Windows only, apparently -- but it's a bit of a faff:

az login  # I assume there's a way to login unattended
az account set --subscription SUBSCRIPTION_ID
az network bastion tunnel --name BASTION_NAME --resource-group RG_NAME --target-resource-id REALLY_LONG_VM_RESOURCE_ID --resource-port 22 --port 2222 &
ssh -i /path/to/private.key -p 2222 user@localhost

Is there a non-proprietary way of SSH'ing into an Azure VM through an Azure Bastion? Or is my assumption on its use-case off?

已采纳解答

原帖链接 · Sam Cogan · CC BY-SA 4.0

You really only have two ways to connect to Bastion with SSH, using a local client, and both involve the Azure CLI:

  • Using Az Network Bastion Tunnel, as you mentioned, to create a tunnel and then connect however you want
  • Using Az Network Bastion SSH to use the native client directly

You could automate this connection if you wanted to connect using a service principal, but assuming you want to connect as a user then it would be a bit of a pain having to store the users credentials and deal with MFA etc.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-02-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。