Accessing the VM with SSH
Overview
Teaching: 10 min
Exercises: 20 minQuestions
How do I connect to my Azure VM?
Objectives
Establish an SSH connection to the Azure VM using PuTTY.
Configure PuTTY to establish tunnels for VNC, and Jupyter connections
Secure Shell (SSH)
You can use any SSH client to connect to your VM. Here, we provide the steps using PuTTY for Windows and Linux operating systems.
For Linux
-
Open a terminal on your Linux machine and navigate to the path of the .pem file you downloaded from Azure before.
-
Set the correct permissions for the pem file by running the following command:
chmod 600 <VMName>_key.pem
-
Execute the following command:
ssh -i <VMName>_key.pem -L 5901:localhost:5901 -L 6080:localhost:6080 -L 8888:localhost:8888 azureuser@<AZURE_VM_IP>
For Windows
Using Windows Subsystem for Linux (WSL)
Using WSL, users can seamlessly operate within their Ubuntu shell and effortlessly follow the Linux instructions.
Using Command Prompt
-
Open Command Prompt.
-
Run the following command:
ssh -i C:\Users\<WindowsUserName>\Downloads\<VMName>_key.pem -L 5901:localhost:5901 -L 6080:localhost:6080 -L 8888:localhost:8888 azureuser@<VM_IP>
Using the PuTTY application
-
Download the latest version of PuTTY from the official website: PuTTY
-
Open
PuTTYgen
and select theConversions
option. -
Then, choose
Import key
to locate and select the.pem
file you downloaded previously from Azure.
Note: Do not select
Generate
.
-
Go to the
File
menu, selectSave private key
, and confirm by clickingYes
in the pop-up window. -
Save the new file as
Any_name_you_want.ppk
to your computer. -
Close the PuTTYgen window.
Configuration of PuTTY
-
Open PuTTY and navigate to the left part of the PuTTY window. Select Category > Session and fill in the following values:
- Host Name (or IP address):
Azure_VM_IP
- Port:
22
- Host Name (or IP address):
-
In the left part of the PuTTY window, select Category > Connection > SSH > Auth. Under
Private key file for authentication
, click onBrowse
and load the.ppk
file created earlier. -
For VNC connections, navigate to Category > Connection > SSH > Tunnel.
- To add the VNC tunnel, set Source Port to
5901
, Destination tolocalhost:5901
, and click the Add button. - To add the WebVNC tunnel, set Source Port to
6080
, Destination tolocalhost:6080
, and click the Add button. - To add the Jupyter tunnel, set Source Port to
8888
, Destination tolocalhost:8888
, and click the Add button.
Note: Tunnels will be required later. They will allow you to easily connect to VNC or Jupyter when the corresponding container is launched.
- To add the VNC tunnel, set Source Port to
-
After defining the above tunnels, save the SSH connection settings and establish the connection by clicking the
Open
button. In the pop-up window, selectAccept
and enter the VM credentials (by default,azureuser
).
Congratulations! You now have remote access to your VM created in Azure.
Key Points
Once connected, you will have command-line access to the VM, allowing you to execute commands and perform administrative tasks remotely.