Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Azure icon
Labs

Remote Administration with PowerShell Core in Linux

This hands-on lab introduces the pratcice of ssh remote administration using PowerShell Core for Linux. In this lab, we cover the following topics: - The creation of multiple Linux virtual machines in Azure. - The installation of PowerShell and its prerequisites on said virtual machines. - The installaion and configuration of ssh on the virtual machines to allow for remote ssh connections. - The creation of ssh remote PowerShell sessions between two Linux virtual machines.

Azure icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 1h 30m
Published
Clock icon Apr 24, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Create Two Linux Virtual Machines in the Azure Portal

    1. Log into the MS Azure Portal using the provided username and password.

    2. Click on Virtual Machines and then click on the + Add button to create a new virtual machine.

    3. Under the resource group settings, click the dropdown menu and select the existing resource group.

    4. In the Virtual machine name box, enter a name for the virtual machine we are creating. In the video, we name the VM UbuntuTest1.

    5. Select the Region dropdown box and change the region to WestUS.

    6. Ensure that the Image is set to Ubuntu Server 18.04 LTS.

    7. Change the size of the virtual machine to B2ms and click Select.

    8. Under the Administrator account settings, click Password for Authentication Type and enter a username and password (x2) which we will use to log in to the virtual machine.

    9. Under Inbound Port Rules, ensure that Allow selected ports and SSH(22) are selected.

    10. Click on Next : Disks >.

    11. Under Disk Options - OS Disk Type, select the dropdown menu and choose Standard HDD.

    12. Click Next : Networking >

    13. Click Next : Management >

    14. Under Monitoring - Boot Diagnostics, select Off.

    15. Click Review + Create.

    16. Finally, click Create and wait for the VM to finish creation.

    17. In the meantime, repeat steps 2 through 16, only name the second virtual machine to something else. In this lab, we named the second VM UbuntuTest2.

    18. Click Home and then click Virtual Machines to ensure that both virtual machines have been created and are present in the list.

  2. Challenge

    Install PowerShell and All Prerequisites on Both Linux Virtual Machines

    1. In the Virtual Machine list, click on the name of the first virtual machine. Off to the right of the screen is the public IP address for the VM. Copy this IP address.

    2. Using the Azure Cloud Shell in Bash mode, connect to the first virtual machine. If there is not storage, create a storage account by clicking Show Advanced Settings, changing the region to West US, using the existing accounts, and creating a new file share with all lowercase leters. In this example, we used filesharetest.

    ssh <username>@<publicipaddress>
    
    1. To install PowerShell, we need to first install the prerequisites. First, download the Microsoft repository GPG keys.
    wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
    
    1. Register the Microsoft repository GPG keys.
    sudo dpkg -i packages-microsoft-prod.deb
    
    1. Update the list of products.
    sudo apt-get update
    
    1. Enable the universe repositories.
    sudo add-apt-repository universe
    
    1. Now we can install PowerShell.
    sudo apt-get install -y powershell
    
    1. Start PowerShell.
    pwsh
    
    1. Exit PowerShell and then exit the ssh session with the first VM.
    exit
    exit
    
    1. Repeat steps 1 through 10 for the second virtual machine. In our lab, the second VM is named UbuntuTest2.
  3. Challenge

    Install OpenSSH Client and Server on Both VMs

    1. Log back in to the first VM with the public IP address using SSH.
    ssh <username>@<publicIPof1stVM>
    
    1. Install Ubuntu OpenSSH server.
    sudo apt install openssh-client
    sudo apt install openssh-server
    
    1. Edit the sshd_config file at /etc/ssh.
    sudo vi /etc/ssh/sshd_config
    
    1. In the sshd_config file, edit the PasswordAuthentication line, ensure it is uncommented and set to yes. Also, add a PowerShell subsystem entry.
    PasswordAuthentication yes
    
    Subsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile
    
    1. Save the file in vi by pressing ESC, and then :wq

    2. Restart the sshd service.

    sudo service sshd restart
    
    1. Exit the ssh session.
    exit
    
    1. Repeat steps 1 through 7 for the second virtual machine.
  4. Challenge

    Working with PowerShell SSH Remoting

    1. Log back in to first virtual machine via ssh and enter PowerShell.
    sudo pwsh
    ssh <username>@<PublicIPofFirstVM>
    
    1. Create a new PowerShell session with the second virtual machine using a variable and the New-PSSession cmdlet.
    $session = New-PSSession -HostName <2nd VM Public IP Address> -Username <AdminUserfor2ndVM>
    
    1. Call the variable to see if PowerShell session has been created.
    $session
    
    1. Enter the PowerShell session to ensure connectivity and run a uname -a command.
    Enter-PSSession $session
    uname -a
    Exit-PSSession
    
    1. Invoke a PowerShell cmdlet to the loaded session and run a Get-Process cmdlet.
    Invoke-Command $session -ScriptBlock { Get-Process }
    
    1. Find the pwsh process on the second virtual machine session.
    Invoke-Command $session -ScriptBlock { Get-Process pwsh }
    
    1. Exit PowerShell and the terminal.
    exit
    exit
    

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans