2

Goal: Add MSYS2/MinGW64 BASH as an optional shell to an existing OpenSSH server with automation purposes in mind.

Constraints:

  • Not Windows 10. WSL is not an option.
  • Shared work environment. Shouldn't "pee in the other kids' pool" beyond what's avoidable.
  • Keep PowerShell Core as primary SSH shell.
  • Have MSYS2/MinGW64 available with minimal overhead as needed.
  • Automation is key.

Setup:

Following instructions from various Microsoft sources:

I have successfully gotten PowerShell over SSH working. However, I have the (more-than-occasional) need to run the MSYS2/MinGW Bash shell.

What KINDA works:

  • running bash in ssh from the CLI: ssh dms3@somehost C:/MSYS64/usr/bin/bash.exe --login (No prompt, can't re-enable in PS1)

  • Setting the Bash exe as a subsystem: (same as above in best-cases, freezes in others) Subsystem bash c:/MSYS64/usr/bin/bash.exe --login

Both are possibly "good enough" for automation.

What would work, but I'd rather not do:

  • Running MSYS sshd as a second SSH server on a different port.
  • Running Bash after logging into Powershell

What I can't do

  • Use a Linux VM.
  • Use WSL.

2 Answers 2

0

Don't know whether this helps, but I'm using the included Win10/11 OpenSSH server. On the Windows SSH server I use CMD as my default shell & I've setup an Environmental variable for my user acct that acts as an alias to start the MSYS shell:

Variable name : MSYS

Value : "msys2_shell.cmd -defterm -msys -no-start -where C:\Tools\msys64\home\\%UserName%"

NOTE: the MSYS64 directory has to be in your environmental PATH variable so msys2_shell.cmd can be found.

From my SSH client I manually log into the Win SSH server with the std SSH command:

ssh user@host

which gets me the default CMD prompt shell on the server. At the prompt I use the MSYS Environmental variable I created as an alias command by typing:

%msys%

This launches the MSYS Bash shell & sets my working directory to my MSYS home directory. However, there's a problem. The MSYS environmental variable HOME is set to the Windows UserProfile path and the .bashrc file is not read. To fix the MSYS HOME, I've added ' export HOME="/home/username" ' to the .bashrc file. After using the %msys% variable as an alias to log in, I run the following command to read the .bashrc file:

. /home/username/.bashrc

The MSYS HOME value gets changed as a result of the export command I added.

If my Win SSH server was set to use the Powershell shell as the default shell I would try using the Powershell environmental alias construct:

$env:MSYS

to start the MSYS Bash shell. This does not work however. Powershell does not accept the environmental variable as an alias for a command. I suggest setting up an alias in the SSH server's Powershell $PROFILE.

0

This worked for me

Run in administrative powershell

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\msys64\usr\bin\bash.exe" -PropertyType String -Force

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .