All Products
Search
Document Center

:Use the Cloud Assistant Agent to install OpenSSH on a Windows ECS instance

Last Updated:May 11, 2023

The Cloud Assistant Agent is a program that runs Cloud Assistant commands on Elastic Compute Service (ECS) instances. This topic describes how to use the Cloud Assistant Agent to install OpenSSH on an ECS instance that runs a Windows operating system.

Prerequisites

  • The Cloud Assistant Agent is installed on the ECS instance on which you want to install OpenSSH. For more information, see Install the Cloud Assistant Agent.

  • Rules are added to the security groups of the ECS instance to allow traffic on SSH port 22. For more information, see Add security group rules.

    Note

    For information about the operating system versions that support Cloud Assistant, see the Limits section of the Overview of Cloud Assistant topic.

Procedure

  1. Log on to the ECS console.

  2. In the left-side navigation pane, choose Maintenance & Monitoring > ECS Cloud Assistant.

  3. In the left part of the top navigation bar, select a region.

  4. On the Cloud Assistant page, click Create or Run Command.

  5. In the Create Command panel, configure the parameters described in the following table.

    Parameter

    Description

    Command Source

    Select Enter Command Content to create a command.

    Command Name

    Enter a name for the command.

    Execution plan

    Select Immediate execution.

    Command Type

    Select a type of command.

    For Windows ECS instances, select PowerShell.

    Command

    Paste the following content to the code editor:

    $curDir = $PSScriptRoot
    Set-Location $curDir
    # Check the OS version
    $OSversion = [Environment]::OSVersion.Version
    if ($OSversion.Major -lt 6 -and $OSversion.Minor -lt 1) {
         throw "This scrip is not supported on Windows 2008 or lower"
    }
    $Arch =([Array](Get-WmiObject -Query "select AddressWidth from Win32_Processor"))[0].AddressWidth
    if ($Arch -ne "64") {
        throw "Only 64-bit system architecture is supported"
    }
    function Check-Env() {
        $srv_status = (Get-WmiObject -Class win32_service -Filter "name= 'sshd'").Status
        if ( $srv_status -match "OK") {
            Write-Host "system already installed opensshd"
            exit
        }
    }
    function Download-File($file_url = "{{sshd_download_url}}", $file_path = "C:\Programdata\OpenSSH-Win64.zip") {
        if (Test-Path $file_path) { return; }
        [System.Net.ServicePointManager]::SecurityProtocol=[System.Net.SecurityProtocolType]::Tls12
        Invoke-WebRequest -Uri $file_url  -OutFile $file_path -UseBasicParsing
        if (! $?) { throw "$file_url download to $file_path error" }
    }
    
    function Unzip-File($src_file = "C:\Programdata\OpenSSH-Win64.zip", $dst_file = "C:\Programdata") {
        Expand-Archive -Path $src_file -DestinationPath $dst_file 
        if (! $?) { throw "Unzip $src_file to $dst_file error, please check" }
    }
    function Install-Ssh() {
        powershell.exe -ExecutionPolicy Bypass -File C:\Programdata\OpenSSH-Win64\install-sshd.ps1
        if (! $?) {
            throw "Install openssh error, please check"
        }
        Start-Service sshd
        Set-Service -Name "sshd" -StartupType Automatic; Start-Service sshd
        if (! $?) {
            throw "set sshd enable auto start or start sshd error , please check"
        }
    }
    Check-Env
    Download-File
    Unzip-File
    Install-Ssh

    Use Parameters

    Turn on Use Parameters. Configure the sshd_download_url parameter. For example, set the sshd_download_url parameter to https://********-cn-hangzhou.aliyuncs.com/OpenSSH-Win64.zip.

    Note

    The sshd_download_url parameter specifies the URL from which you want to download the sshd installation package. Set the sshd_download_url parameter to the URL from which you want to download the sshd installation package.

    Command Description

    Enter a description for the command. We recommend that you enter identifiable information, such as the purpose of the command, to facilitate management and maintenance.

    Username

    Specify the username to use to run the command on ECS instances.

    For security purposes, we recommend that you run Cloud Assistant commands based on the principle of least privilege as a regular user. For more information, see Configure a regular user to run Cloud Assistant commands.

    Note

    By default, Cloud Assistant commands are run by the root user on Linux instances and by the system user on Windows instances.

    Execution Path

    Specify an execution path for the command. Different default execution paths are provided based on the operating system of instances on which the command is run.

    For Windows instances, the default execution path is the following directory in which the process of the Cloud Assistant Agent resides: C:\ProgramData\aliyun\assist\$(version).

    Timeout Period

    Specify a timeout period for the command to run on instances. If a task that runs the command times out, Cloud Assistant forcefully terminates the task process.

    Unit: seconds. Default value: 60. We recommend that you set the value to 300. The value can be adjusted based on the network conditions.

    Select Instances

    Select the ECS instances on which you want to run the command.

    Select Managed Instances

    Select the managed instances on which you want to run the command.

    Note

    A managed instance is an instance that is not provided by Alibaba Cloud but managed by Cloud Assistant. For more information, see Manage servers that are not provided by Alibaba Cloud.

  6. Click Save to run the command.

  7. Install OpenSSH.

    1. Connect to the Windows instance by using Virtual Network Computing (VNC).

      For more information, see Connect to a Windows instance by using a password.

    2. Click the Dingtalk_20210510142550.jpg icon and select Windows PowerShell to start PowerShell.

    3. Run the following command to install OpenSSH:

      NETSTAT.EXE -ano

      The following figure shows a sample command output, which indicates that OpenSSH is installed and listens on port 22.

      1be53a98a94bf5f6be7418edb4cf669bd49b8810ac54fbc73d5340136041ca9aQzpcVXNlcnNcbGl4aWFuZ1xBcHBEYXRhXFJvYW1pbmdcRGluZ1RhbGtcMTM3MTc0NDY0X3YyXEltYWdlRmlsZXNcMTYyNDI1NzY5NDUxNl9GNUNEMDFFNC1CQThCLTQ1MTItODNFNC1EM0ZCR.png
  8. Use an SSH client to connect to the Windows instance.

    Note

    Use the current username and password of the Windows instance to log on to the instance.