DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

Create an Azure VM and connect with SSH (Mac)

Part A — Create the VM in Azure Portal

  1. Azure Portal
  • Go to portal.azure.com
  • Search: Virtual machines
  • Click CreateAzure virtual machine
  1. Basics tab
  • Subscription: choose your subscription
  • Resource group: Create new (example: rg-devops-lab)
  • Virtual machine name: vm-lab-1
  • Region: pick one (example: East US)
  • Availability options: leave default (or “No infrastructure redundancy required” for simplest)
  • Image: Ubuntu Server 24.04 LTS
  • Size: pick something small (example: Standard_B1s or Standard_B2s if available)
  1. Administrator account (SSH)
  • Authentication type: SSH public key
  • Username: azureuser
  • SSH public key source:

    • Choose Generate new key pair (recommended if you don’t have one)
  • Key pair name: vm-lab-1_key

  1. Inbound ports
  • Select Allow selected ports
  • Choose SSH (22)
  1. Click Review + create
  • If validation passes, click Create
  • Azure will prompt to Download private key → download the .pem file

    • Save it safely (usually in ~/Downloads)

Part B — Get the Public IP

  1. After deployment:
  • Go to Virtual machines → open your VM
  • Copy Public IP address (example: 20.x.x.x)

Part C — SSH from Mac Terminal

  1. Open Terminal and go to where the key is (example Downloads):
cd ~/Downloads
ls
Enter fullscreen mode Exit fullscreen mode
  1. Fix permissions on the key (required):
chmod 400 vm-lab-1_key.pem
Enter fullscreen mode Exit fullscreen mode
  1. Connect with SSH:
ssh -i vm-lab-1_key.pem azureuser@<PUBLIC_IP>
Enter fullscreen mode Exit fullscreen mode

Example:

ssh -i vm-lab-1_key.pem azureuser@20.83.170.33
Enter fullscreen mode Exit fullscreen mode
  1. First-time prompt:
  • Type yes and press Enter

You should land in:

azureuser@vm-lab-1:~$
Enter fullscreen mode Exit fullscreen mode

Common problems (quick fixes)

1) Permission denied (publickey)

You forgot -i or used the wrong key:

ssh -i correct_key.pem azureuser@<PUBLIC_IP>
Enter fullscreen mode Exit fullscreen mode

2) UNPROTECTED PRIVATE KEY FILE

Permissions are too open:

chmod 400 *.pem
Enter fullscreen mode Exit fullscreen mode

3) SSH times out / hangs

Port 22 blocked:

  • Azure Portal → VM → Networking
  • Ensure Inbound rule allows TCP 22
  • If you restricted Source to your IP, verify your current public IP

Top comments (0)