How to create Azure Virtual Machine and perform login using SSH

From PUBLIC-WIKI
Jump to navigation Jump to search

Generating SSH keys (from Windows machine)

  • Download puttygen.exe from:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
  • Run the puttygen.exe
  • Click Generate and follow the on-screen instructions to generate a new key.
Note: Make sure you create keys with at least 2048 bits
  • Click Save private key to write your private key to a file with a .ppk extension.
  • Click Save public key to write your public key to a file for later use.

Generating SSH keys (from Linux machine)

  • Login to the Linux machine console
  • Run the following command to generate the SSH key pair:
ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME]
Note: Replace KEY_FILENAME with the actual private key file name
  • Change the permissions of the SSH private key using the command below:
chmod 400 ~/.ssh/[KEY_FILENAME]
Note: Replace KEY_FILENAME with the actual private key file name

Create Azure VM from the management console

  • Login to the Azure Portal:
https://portal.azure.com
  • From the left pane, click on “Virtual machines” -> from the main pane, click on “Create Virtual machines” -> select a Linux flavor -> select a deployment model -> choose “Resource Manager” -> click on Create
  • Fill-in the following details:
  • Name: Specify here machine hostname
  • VM disk type: Select the disk type according to your needs. For more information and pricing details, see:
https://azure.microsoft.com/en-us/pricing/details/managed-disks/
  • User name: Specify here the username of the administrator of the VM
  • Authentication type: Select “SSH public key”
  • SSH public key: Open the previously created public key (usually it has no file extension) using a text editor and copy its entire content into memory and paste the content of the public key into the free text field
  • Subscription: Select an existing Azure subscription
  • Resource group: Select either existing or create a new resource group. For more information, see:
https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-overview#resource-groups
  • Location: Select a region close to your location
  • Click OK
  • Choose a size -> select VM type according to your needs. For more information and pricing, see:
https://azure.microsoft.com/en-us/pricing/details/virtual-machines/linux/
  • Click Select
  • Fill-in the following details:
  • Availability set: Select this option in case your virtual machine requires high availability. For more information, see:
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/tutorial-availability-sets
  • Disk type and managed disks: Select the settings according to your needs. For more information and pricing details, see:
https://azure.microsoft.com/en-us/pricing/details/managed-disks/
  • Virtual network: Select a VNet according to your needs. For more information, see:
https://docs.microsoft.com/en-us/azure/virtual-network/virtual-networks-overview
  • Subnet: Select the relevant subnet. For more information, see:
https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-manage-subnet
  • Public IP address: Leave the default settings
  • Network security group: Select either to create a new network security group or to select an existing network security group. For more information, see:
https://docs.microsoft.com/en-us/azure/virtual-network/security-overview
  • Extensions: Leave the default settings
  • Enable auto-shutdown: Select either off (the virtual machine will remain up and running) or on (and configure automatic shutdown on daily basis). For more information, see:
https://blogs.msdn.microsoft.com/uk_faculty_connection/2017/09/12/azure-virtual-machine-auto-shutdown/
  • Monitoring: Leave the default settings
  • Click OK
  • Click Create

Login to Azure Virtual machine (from Windows machine)

  • Login to the Azure Portal:
https://portal.azure.com
  • From the left pane, click on “Virtual machines” -> locate the relevant virtual machine -> click on the machine name -> from the overview page, write down the "Public IP address" (or "DNS name", if configured)
  • Download Putty from:
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
  • Run putty.exe
  • From the left pane, under “Connection” -> expand SSH -> click on “Auth” -> from the main pane, under “Authentication parameters”, click on “Browse” -> locate the SSH private key generated by puttygen.exe
  • From the left pane, click on “Session” -> from the main pane, under “Host Name (or IP address)” specify the following:
Username@IP_Address
Note 1: Replace Username with the account name created during the VM creation phase
Note 2: Replace IP_Address with the Virtual machine “Public IP address” or "DNS name"
  • Under “Saved Sessions”, specify a name for this newly created connection.
  • Click on Save
  • Click on Open

Login to Azure Virtual machine (from Linux machine)

  • Login to the Azure Portal:
https://portal.azure.com
  • From the left pane, click on “Virtual machines” -> locate the relevant virtual machine -> click on the machine name -> from the overview page, write down the "Public IP address" (or "DNS name", if configured)
  • Login to the Linux machine console
  • Copy the private key file into ~/.ssh of the currently running user
  • Run the following command:
ssh Username@IP_Address -i ~/.ssh/[KEY_FILENAME]
Note 1: Replace Username with the account name created during the VM creation phase
Note 2: Replace IP_Address with the Virtual machine “Public IP address” or "DNS name"
Note 3: Replace KEY_FILENAME with the actual private key file name