Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ssh to Azure VM using private IP address from internet

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.
like image 399
SeaDude Avatar asked May 27 '18 03:05

SeaDude


People also ask

Can I connect to Azure VM with Private IP?

IP-based connection lets you connect to your on-premises, non-Azure, and Azure virtual machines via Azure Bastion over ExpressRoute or a VPN site-to-site connection using a specified private IP address.

Can Azure VM access Internet without public IP?

You don't need Public IPs to access your VMs over RDP/SSH. Additionally, Azure Bastion provides integrated connectivity using RDP/SSH directly from your browser and the Azure portal experience. You don't need an additional client, agent, or piece of software.

How do I access Azure VM from outside network?

Arguably, the preferred way to access Azure VM from outside is the Azure Bastion host PaaS service. This is a relatively newer service from Microsoft that allows users to access internal VMs without using an external IP address on the internal virtual machines.


2 Answers

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

like image 129
Joel Guerra Avatar answered Sep 28 '22 06:09

Joel Guerra


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.

like image 20
Haneef Mohammed Avatar answered Sep 28 '22 07:09

Haneef Mohammed