8

Using Cygwin environment on Windows is a very common solution for automation.

I am looking for a script that would automate the cygwin installation and enablement of ssh server.

I could try to write one but one of the problems is that I don't know what I can use to download line for downloading cygwin.

sorin
  • 7,668
  • 24
  • 75
  • 100

3 Answers3

6

Automating the Cygwin installation is described here. Once you've installed Cygwin, you need to run ssh-host-config to set up the ssh server. I don't know how easy that is to automate, but maybe you could do something with expect, and chain the two scripts together.

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
4
Write-Host "Downloading Cygwin ..." -ForegroundColor Cyan
$cygwinSetup = '{0}\cygwin-setup.exe' -f $env:SystemDrive
$startBitsTransfer = @{
    Source      = 'https://www.cygwin.com/setup-x86.exe'
    Destination = $cygwinSetup
    ErrorAction = 'Stop'
}
if ([Environment]::Is64BitOperatingSystem) {
    $startBitsTransfer.Source = 'https://www.cygwin.com/setup-x86_64.exe'
}
try {
    Start-BitsTransfer @startBitsTransfer
} catch {
    (New-Object Net.WebClient).DownloadFile($startBitsTransfer.Source, $startBitsTransfer.Destination)
}



Write-Host "Installing Cygwin & Packages ..." -ForegroundColor Cyan
$run = @{
    FilePath = $cygwinSetup
    ArgumentList = @(
        '--quiet-mode',
        '--upgrade-also',
        '--delete-orphans',
        '--disable-buggy-antivirus',
        '--root', ('{0}\cygwin' -f $env:SystemDrive),
        '--site', 'http://cygwin.mirror.constant.com',
        '--local-package-dir', ('{0}\Downloads' -f $env:PUBLIC),
        '--packages', 'git,curl,jq,libcurl,openssh,cygrunsrv,more,grep,stat,cygpath'
    )
    Wait = $true
    PassThru = $true
}
$result = Start-Process @run
Write-Host "Return Code: $($result.ExitCode)" -ForegroundColor Magenta



Write-Host "Configure SSH ..." -ForegroundColor Cyan
$run = @{
    FilePath     = 'C:\cygwin\bin\bash.exe'
    ArgumentList = @(
        '--login',
        '-c',
        '"/bin/ssh-host-config', '--yes', '--port', 22, '--pwd', (New-Guid), '|', 'more', '/E', '/P"'
    )
    Wait         = $true
    PassThru     = $true
}
$result = Start-Process @run
Write-Host "Return Code: $($result.ExitCode)" -ForegroundColor Magenta



Write-Host "Enable SSH Firewall ..." -ForegroundColor Cyan
New-NetFirewallRule -DisplayName "Allow SSHD" -Direction Inbound -Action Allow -EdgeTraversalPolicy Allow -Protocol TCP -LocalPort 22
VertigoRay
  • 212
  • 1
  • 2
  • 9
0

FWIW, I created a package called CygSSH that's basically a convenient packaging of the Cygwin version of OpenSSH (server and/or client) and rsync. It's on GitHub:

https://github.com/Bill-Stewart/CygSSH

The Releases tab has the installer executable.

Bill_Stewart
  • 258
  • 1
  • 7