Configuring cygwin sshd-host-config through script on REMOTE Windows hosts - cygwin

I'm trying to Install CYGWIN on Win2016 and 2012 server and configure sshd-host-config for for an agent server to push agent to the target windows VMs. I some how googled and managed to get PS code to install CYGWIN 64 bit version but i'm looking to automate the configuration of sshd-host-config(this is an interactive and asks for multiple yes/no input and a text) and net-start-sshd after configuration. Could any one help on this please? Thanks in advance.
Here is the piece of code for installing CYGWIN: (i got this code by googling and not my own piece)
$exeFilePath = "C:\cygwin64\setup-x86_64.exe"
(New-Object Net.WebClient).DownloadFile('http://www.cygwin.com/setup-x86_64.exe', $exeFilePath)
Start-Process "C:\cygwin64\setup-x86_64.exe" -ArgumentList "--quiet-mode --root C:\cygwin64 --site http://cygwin.mirror.constant.com --packages `"curl,python,python-crypto,openssl,openssh,zip,unzip`"" -Wait -NoNewWindow;
Write-Host "Installed Cygwin x64" -ForegroundColor Green ```

Related

Installing Anaconda on Linux VM Instance on Google Cloud Platform

I have provisioned a VM (ubuntu-minimal-1804) on google cloud platform. I want to install anaconda3 and run jupyter notebooks on it. I lack the Computer Science/ IT background and hence tried to follow the online resources. I am finding it difficult install the anaconda3 and jupyter on the VM despite following these sources. Can anyone help me with this? I would really appreciate if anyone can provide me with step-by-step guide.
Note: These are the links that I followed but failed to install anaconda
https://www.cloudbooklet.com/how-to-install-anaconda-on-ubuntu-18-04-lts-google-cloud/
https://www.datacamp.com/community/tutorials/google-cloud-data-science
Thank you in advance
The steps that you have followed should be applicable to your Ubuntu 18.04 LTS VM (with the official image and default setup), after locating it in your instances list and clicking on the SSH button.
Despite the "minimal" images lacking some of the commonly-used utilities in Ubuntu, I could test the commands in the guide in a new VM from the ubuntu-minimal-1804-lts image family and managed to successfully install Anaconda3, except for the VSCode installation that seemed to have an outdated server connection check.
I would also recommend trying the latest installer for Anaconda3 that's available in the repo archive instead, as the one in the guide is a bit outdated:
$ curl -O https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh
$ rm -rf ~/anaconda3 # (clear previous attempted installation first, if any)
$ bash Anaconda3-2020.11-Linux-x86_64.sh
In any case, as suggested by John Hanley, feel free to comment below or edit your question with any errors that you might get.

How to make WSL Ubuntu 1804 understand that WSL is enabled in Windows?

I try to install WSL on Windows 10, and since I don't have Microsoft Store in it, I try to install WSL via URL. I tried to use this manual, and I've got a problem.
Firstly, what's odd, when I try to download .appx file from the URL, I actually download .zip file. Then I extract it to desktop and try to run ubuntu.exe (having Windows Subsystem for Linux enabled in settings). I receive an error The Windows Subsystem for Linux optional component is not enabled. Please enable it and try again. See https://aka.ms/wslinstall for details.
What am I doing wrong? It would be very helpful for me if anybody helped me with this problem.
Before being able to use WSL you need to enable the "Windows Subsystem for Linux" optional feature. You can enable it by running:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
More installation instructions can be found here.

Error while trying to install Node, and its related programs, and apparently because I can't get TLS 1.2 support in Windows 7

I tried to install Node, plus any extra tools it optionally 'needs' which apparently included "Chocolatey".
("Chocolatey" is a poorly named package manager. The developer of it saw that Visual Studio IDE has NuGet, he thought it'd be good if Windows had a package manager, just as unix-based OSs have package managers like debian has apt-get or osx has brew and macports, and he made one for windows called - "Chocolatey" as his joke, and it has some growing amount of software it supports. e.g. I see you can do choco install vlc to install VLC media player. I don't know what software Node would use it to install but anyhow)
I tried to install Node and I think I ticked the box for it to install other software that it needs. It required me to close all my programs, which I did.
I got this error during the install
I searched that error "Exception calling "DownloadString" with "1""
And I got this https://chocolatey.org/docs/troubleshooting
"If you see the following: Exception calling "DownloadString" with "1" argument(s): "The request was aborted: Could not create SSL/TLS secure channel." then you are likely running an older machine that needs to be upgraded to be able to use TLS 1.2 at a minimum."
I find that strange, since TLS 1.2 was released a long while back as seen on this page. https://kinsta.com/knowledgebase/tls-vs-ssl/ TLS 1.2 was released in 2008. I'd be surprised if Windows 7 doesn't support it, since Windows 7 only reached end of life Jan 2020. Even TLS 1.3 was released in 2018.
When searching the error, I found this page https://support.cybersource.com/s/article/How-do-I-enable-TLS-1-2-on-Windows-7
It mentioned certain registry keys that it says I needed.
According to https://chocolatey.org/blog/remove-support-for-old-tls-versions
While your operating system may support TLS 1.2 it's important to remember that it may have to be enabled. If you are working from
PowerShell you can find out which protocols your system supports by
running this code:
[Enum]::GetNames([Net.SecurityProtocolType]) -contains 'Tls12'
Copy
If the result is True then your system supports TLS 1.2.
And it then goes on to say if it is supported how to check if it is being used.
But for me
TLS 1.2 shows as not supported
PS C:\Users\User> [Enum]::GetNames([Net.SecurityProtocolType]) -contains 'Tls12'
False
I saw this page https://support.cybersource.com/s/article/How-do-I-enable-TLS-1-2-on-Windows-7
And made this reg file
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server]
"DisabledByDefault"=dword:00000000
I notice I have a key (folder on the left hand side), in regedit called SSL 2.0 Not sure what, if anything, should be in there
I tried restarting but still running the mentioned powershell command gave false, indicating TLS 1.2 not supported.
You need add these values to yours register keys:
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
They were took from Sanjeev Kumar's answer in node.js installation error in windows 10 in vscode
... and worked for me.

Docker on Windows 2019 cannot switch to Linux OSType

I'm unable to switch docker to run in Linux mode on a 2019 Windows Server. I've found several guides online that show how to do this via powershell. After running the PS scripts I've noticed no virtual machine is installed in hyper-v, and after a server restart docker is still running in windows mode.
I enabled the Hyper-V windows role, and the Containers role. Docker seems to work fine in windows mode, I just can't get it to switch over to Linux.
Here is the PS I've executed trying to make the switch:
Install-Module DockerProvider
Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview
(Reboot machine)
[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", "1", "Machine")
Restart-Service docker
When I run docker info it continues to show OSType: windows. Also, when I view Hyper-V Manager I expected to see a VM for running Linux however there are no VMs. I think that might be related to the problem.
So I was able to resolve this issue. I'm currently running a Linux container in Docker on a Windows 2019 server, yet the OSType still says Windows... I guess I shouldn't expect that value to ever change to Linux (on my local Windows 10 machine it says OSType: Linux)?
Anyway, here are the steps I went through to get Linux containers running on my Windows 2019 server:
Enable Hyper-V and Containers via Server Manager -> Add roles and features
Restart the server
Open Powershell and run the following commands
Powershell Scripts:
Install-Module "DockerMsftProvider" -Force
Update-Module "DockerMsftProvider"
Install-Package Docker -ProviderName "DockerMsftProvider" -Update -Force
NOTE: If prompted to install a Nuget provider type Y
Set-Content -Value "`{`"experimental`":true`}" -Path C:\ProgramData\docker\config\daemon.json
restart-service docker
This is where I found the solution: https://www.b2-4ac.com/lcow-linux-containers-on-windows-server/

Trying to use bash on Windows and got no installed distributions message

I am trying to use bash on Windows 10, but I'm getting this message when tried to run bash:
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Windows Store:
https://aka.ms/wslstore Press any key to continue...
When I go to that url which opens the Windows Store app, there no sign of any Linux distribution there.
My windows version is(as in my right bottom corner of the screen):
Windows 10 Enterprise Insider Preview. Evaluation copy.Build
16215.rs_prerelease.170603-1840
I follow the instructions in this guide Installation Guide and also was watching this video Editing code and files on Windows Subsystem for Linux on Windows 10 from Scott Hanselman, but they didn't get the message of no installed distribution.
Any Help?
When the Windows Store opened, there was no Distro to choose, then I found this command lxrun /install and worked for me as well.
You will get something like this as an output:
C:\WINDOWS\system32>lxrun /install
Warning: lxrun.exe is only used to configure the legacy Windows Subsystem for Linux distribution.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore
This will install Ubuntu on Windows, distributed by Canonical and licensed under its terms available here:
https://aka.ms/uowterms
Type "y" to continue: y
Downloading from the Microsoft Store... 100%
Extracting filesystem, this will take a few minutes...
Would you like to set the Ubuntu locale to match the Windows locale (en-FI)?
The default locale is en_US.
Type "y" to continue: y
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: <you type your login here>
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Installation successful!
Documentation is available at: https://aka.ms/wsldocs
I'm getting a similar bug after trying to uninstall and reinstall.
For me I had to open a cmd prompt as administrator and run lxrun /install
I get this when I have recently rebooted. If I wait 5 minutes, the problem fixes itself !
The top answers written for this question are more than enough. I just had trouble following them because lxrun command has been depreceated, so I get the error
'lxrun' is not recognized as an internal or external command, operable
program or batch file.
when I try to run this command with cmd.
It has been replaced with wsl command. You can get more info on this issue here - https://github.com/MicrosoftDocs/WSL/issues/425
When you run wsl /install, there is a chance you may still get the error that you had earlier posted in your question. In that case, simply go to the link https://aka.ms/wslstore as you had gone earlier. If you don't see anything coming up, simply search for Ubuntu and install the same. (If you search with the term wsl though, you will get to see other Linux flavors too and then you can download any of your choice)
It seems that the link given in the command doesn't work. Here's the actual link to the microsoft store for Ubuntu.
https://www.microsoft.com/en-nz/store/p/ubuntu/9nblggh4msv6?rtc=1
You have to go to https://aka.ms/wslstore this link and download ubuntu on windows. After that you can use bash on windows.
If you have any problems with running lxrun /install (for example on ltsb Windows version) try manual mode.
First, go to the folder with downloaded .appx file and run following commands (change filename if needed):
Rename-Item ~/Ubuntu.appx ~/Ubuntu.zip
Expand-Archive ~/Ubuntu.zip ~/Ubuntu
After finishing cd into new folder and run ubuntu.exe file. That's it.
If you get this error after installing a distribution using the windows store, and WSL was working previously, you may need to make sure that the LxssManager service is running, since it often stops after a Windows update or a reboot.
Go to services.msc, and search for LxssManager and start it; if it is running already, restart it.
For everyone who is getting
'lxrun' is not recognized as an internal or external command,
operable program or batch file.
or
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore
Open microsoft store, install 'Ubuntu' then open the app. This will install ubuntu and later you can use wsl command since lxrun is deprecated
Go to add or remove programs
Install Windows subsystem for Linux
Go to https://aka.ms/wslstore, which will take you to the Microsoft Store
Select and install a Linux distribution
lxrun /install
Works on a Administrator Command Prompt for Windows 10 Professional, Version 1803 Build 17134.165
This installs GNU/Linux by default whereas there is an option to select between:
Ubuntu
openSUSE Leap 42
SUSE Linux Enterprise
Debian GNU/Linux
Kali Linux
If the given link (https://aka.ms/wslstore) works, it openes the windows store for me with an error saying something is wrong on their side and to try again later.
It's actually easier to solve this problem that other solutions listed here. If you run wslconfig /l and if the output is:
Windows Subsystem for Linux Distributions:
Ubuntu (Default)
Just run wslconfig /s Ubuntu to set Ubuntu as default again. It should start working now.
Edit:
I've also found that if this problem occurs on a fresh boot, then you just wait for a few minutes (10 minutes max) and this error automatically disappears.
Edit 2:
I've also found that this error is sometimes also due to the corresponding service not running. Run CMD as administrator and run
net start LxssManager
For running bash on windows ubuntu is required to be installed.
As you've already added bash from programs and features, now you need to install Ubuntu. Contrary to what is seen in most of the installation guides on web, it does not gets installed by running 'bash.exe'.
You can simply go to Microsoft store in search for 'Bash' or 'Ubuntu'and install Ubuntu 18 LTS from there.
After installation you'll be able to use the terminal and all its commands.
Run the bash command in git bash windows. It worked !!
As of 2022, New Linux distributions are available for Windows 10 as well as Windows 11 like Kali Linux and Ubuntu. Both available from Microsoft Store. Someone watching this question now can visit Microsoft Store to Download them..
I had this same issue. But when you go to the windows store you can search for ubuntu and then install the ubuntu app and it works. I think most of the tutorials on the net are from the beta version and have afterwards never been updated.
https://insights.ubuntu.com/2017/07/11/windows-10-loves-ubuntu-loveislove/
Note: This is also old. You do not need to be on the insider builds. I'm not and it worked.
The only thing that worked for me is described here https://learn.microsoft.com/en-us/windows/wsl/install-manual#downloading-distros
https://aka.ms/wsl-ubuntu-1804
manually install it or run Add-AppxPackage.\.appx from PowerShell
The link to the store appears to have a region lock in it, resulting in errors for many visitors.
However there are different Ubuntu distributions to be downloaded. See image below, image is however in Dutch but it will show results.
So pick a version you desire and it will result in a working bash.
The actual answer to the question query is: The user exists with Ubuntu already installed. But WSL command does not find anything in CMD.exe "Command Line" "System does not find distribution."
You need to start the below WSL command from Windows Start Menu. And then the old Linux System will show up on WSL in the command line as found.
If this doesn't work for you? Just start up PowerShell with Administrator and:
WSL --help
WSL "only this command, will start the Linux default distro selected"
You can then start up using this command with CMD.exe Administrator in Windows:
lxrunoffline l "This will now list all your distros"
With an option to remove old distros copied to Windows folders are with perhaps Ubuntu18.04 such way that you will have to use Linux to remove older folders, do not try to copy or edit files in a distro with Windows Apps. You risk integrity problems as well as many errors followed by huge processing time. Use folder /mnt to find your drive with Linux and use commands there to further finish your work as perhaps copying the home directory into a new distro.
My solution to move "not copy" my distro then was: "to give space for C:"
lxrunoffline m -n Ubuntu-18.04 -d d:\wslinstalled\Ubuntu-18.04 "remember folder names"
"Remember folder name such as Ubuntu-18.04 for a specific movement. Unless you will overwrite everything on that folder name with also the lxrunoffline files and you risk losing older copies if you use one folder name. You might end up with a strange name to your project if you just use one directory."
Lxrunoffline has several other commands if you need help just run:
lxrunoffline
like beginner_ said in his answer you need to go to the store and look for the distros you want to install.
Please see the following link to understand what has changed and what you can excpect or what distros you can look for(the list is outdated so just try to find an updated list or just try your luck).
I am running on my machine without the developer mode Ubuntu, OpenSuse and Kali.
Access to Microsoft Store is blocked by my company. For me following worked in PowerShell (admin) -
lxrun /install
Go to cmd, and then run the following command:
lxrun /install
Typing lxrun /install in elevated command prompt works....
The solution to the error "WSL 2 installation is incomplete",
Execute the following steps:
wsl --install -d Ubuntu ## lxrun is no more, its now replaced with wsl,
enter image description here
wsl
enter image description here

Resources