2018-07-26

Install both Chocolatey and OpenSSH with SSHD in one Copy-Paste in Powershell




TL;DR



Start a PowerShell console with Administrator privileges and run the following :


[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {[bool]1}; set-executionpolicy RemoteSigned -Force -EA 'SilentlyContinue'; iex ((new-object net.webclient).DownloadString('https://gist.githubusercontent.com/deskobj/f135af9b5404c594ee041c1688bc6f0a/raw')) 


After the command has exited, we can expect the following to be true:
  • CHOCO command available by default via PATH environment variable.
  • SSH command available by default via PATH environment variable.
  • SSHD service is running.






HISTORY OF THE ONE-LINER COMMAND
AND ITS BACK-END SCRIPT



The original command (from DarwinJS/ChocoPackages) reads as follows:
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {[bool]1};set-executionpolicy RemoteSigned -Force -EA 'SilentlyContinue';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/DarwinJS/ChocoPackages/master/openssh/InstallChoco_and_win32-openssh_with_server.ps1'))
Additionally:
  • JUL 26, 2018: Despite the recommendation "Not To", a cached (and modified) version of the script is made available.
  • AUG 28, 2018: Enforced TLS 1.2 security protocol use.
  • MAY 05, 2019: Added information about how to install Chocolatey on its own, using just a command line.




WHAT ABOUT INSTALLING CHOCOLATEY ONLY ?
(WITHOUT THE SSHD SERVICE)



To simply install Chocolatey, without SSH support, run the following PowerShell command, as Administrator:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; set-executionpolicy RemoteSigned -Force -EA 'SilentlyContinue'; iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))

If you wish to install SSH later, you can still run the original command even if Chocolatey is already installed (the Choco installation step will just be skipped).





PREVENT SYSTEMATIC CONFIRMATIONS
(WHEN YOU KNOW WHAT YOU ARE DOING)



Chocolatey always asks if you are sure about installing a piece of software.

One way to address this problem is to always specify the `-y` switch when invoking `choco install`. For instance:

  • `choco install -y git`,
  • or the even shorter version being `cinst -y git`


But you can also disable this behavior altogether, on a global scale, forever, by running the following command:

choco feature enable -n allowGlobalConfirmation




It's probably a dangerous thing to set up, but it's really nice when you are familiar with the tool and use it repeatedly.




MORE SOFTWARE INSTALL SUGGESTIONS



Chocolatey is like a package manager, but for Windows; a bit like the famous `apt-get` or `aptitude` for some GNU/Linux distros (`dpkg` for Debian, `yum` for Fedora/RHEL/CentOS or `dnf` for RPM-based distros in general, `yast2` or `zypper` for OpenSuse, `emerge` for Gentoo, `pacman` for Arch). So it allows you to install software easily and effortlessly and the catalog of supported installs is growing.

I have created a curated list of my favorite ones; the ones I would install right away on a new computer, whether it is for work or even for home computing.

Read more:



Other, ready to paste, multi-line commands such as the one above, can be found on this page:


No comments:

Post a Comment