Azure VM
Access

  • SSH with password access
  • # access with username/password
    # create a user on virtual machine
    sudo useradd -m <username> -s /bin/bash
    
    # add password on virtual machine
    passwd <username>
    
    # login virtual machine with username/password
    ssh username@ip
                
    # access with keys
    # generate a public key and a private key under ~/.ssh on local
    # algorithm, rsa, dsa, ecdsa, ed25519
    ssh-keygen -f [filename] -t [algorithm]
    
    # copy the public key to authorized_keys under ~/.ssh on virtual machine
    
    # login virtual machine with private key from local
    ssh -i <private key> username@ip
                
  • SSH with public key access
  • # change mode to read only
    chmod 400 <private key>
    
    # access with private key
    ssh -i <private key path> username@ip
                
    # create a user on virtual machine
    sudo useradd -m <username> -s /bin/bash
    
    # create authorized_keys under ~/.ssh on virtual machine 
    cd /home/<username>
    sudo mkdir .ssh
    cd .ssh
    sudo touch authorized_keys
    
    # generate a public key and a private key under ~/.ssh on local
    # algorithm, rsa, dsa, ecdsa, ed25519
    ssh-keygen -f [filename] -t [algorithm]
    
    # copy the public key to authorized_keys under ~/.ssh on virtual machine
    
    # login virtual machine with private key from local
    ssh -i <private key> username@ip
                
  • Remote Desktop Protcol (RDP)
  • # Add Inbound port rules in Setting -> Networking
    Priority: 300
    Name: Port_3389
    Port(Destination): 3389
    Protocol: TCP
    Source: Any
    Destinations: Any
    Action: Allow
    
    # test RDP connection in Connect
                
    # Enable rdp on VM
    sudo apt-get -y install xrdp
    sudo systemctl enable xrdp
                
    # Download RDP file to launch Microsoft Remote Desktop
                
  • Bastion
  • # 1. Create a Bastion and create a Virtual Network
    # 2. Create a Virtual Machine
                
    Copy
    # copy from local to VM
    scp -i <private key path> localFile username@ip:./
    
    # copy from VM to local
    scp -i <private key path> username@ip:./path localPath
            
    Running after disconnection
    # keep processes running after SSH session disconnects
    nohup long-running-process &
    
    # view nohup.out
    tail -f nohup.out
                
    VM Scale Set
  • Set of identical virtual machines
  • Automatically scale the amount of virtual machines
  • Reference
  • Install and configure xrdp to use Remote Desktop with Ubuntu
  • Cannot connect remotely to a VM because RDP port is not enabled in NSG
  • Connect to a VM using Remote Desktop Protocol on a Mac