How to ssh to Azure VM using private IP address from internet
Asked Answered
A

3

9

I'm new to Azure. Just deployed an Ubuntu VM but thought I'd only create a private IP address, no public IP.

How do I ssh from my laptop at home to the Azure VM using the 10.x.x.x IP address?

I've tried:

  • Using the Azure Cloud Shell but connection just times out
  • Using ssh on my laptop, but its looking for the VM on my LAN and times out.
Atropos answered 27/5, 2018 at 3:42 Comment(0)
H
7

You can't SSH from your local machine to your VM with a private IP because your machine isn't in the same network as the VM. You would only be able to SSH to the VM from another VM on the same virtual network.

In order to SSH to your VM from outside of the vnet you will need a NIC attached with a Public IP and the default port of 22 open on your Network Security Group.

Edit: because I couldn't find a relevant document for this I wrote a blog post. https://medium.com/@joelatwar/how-to-ssh-to-your-azure-linux-vms-with-username-and-password-from-windows-linux-or-mac-df7d07ea3be1

Headrick answered 27/5, 2018 at 4:6 Comment(3)
Thank you for the answer. And is this true even when using Azure Cloud Shell?Atropos
Yes. Because the Cloud shell, while in Azure, isn't in your vnet. Just like when you type 10.x.x.x from your laptop it only searches your local network.Headrick
What if I don't want to have port 22 open to the internet? Would it be possible to do it with azure load balancer and port forwarding?Unharness
A
4

I have found some other way working.

Temporarily attach the VM with private ip address under a public azure lb, configure a nat rule for ssh in the load balancer.make sure you have allowed the ssh from inside vnet in the nsg where the vm is attached.

SSH into the public load balancer ip and you will be able to access the internal machine via azure load balancer ip.

Aldous answered 31/1, 2019 at 13:20 Comment(0)
C
2

In the meanwhile there exists Azure Bastion which could help you.

Cheddar answered 24/1, 2020 at 12:0 Comment(1)
Provided link directs you to the German page. For non-German speakers like me, here's the English version: azure.microsoft.com/en-us/products/azure-bastionDannettedanni

© 2022 - 2024 — McMap. All rights reserved.