Windows – Install Bash + openSSH on Windows Server 2012

bashsshwindowswindows-server-2012

I had to create a Virtual Machine with Windows Server 2012.
Now I want to connect to it via OpenSSH and Bash, installing OpenSSH is successful, however when I connect to the server via ssh Administrator@<ip> I can only use the Windows Powershell. Is it possible to install a bash (like git bash or cygwin) and to connect via ssh directly to this shell ?

Best Answer

You want to use Cygwin, then use Cygwin, right? A big limitation with my instructions is that it's for a single user at a time, SSH isn't running as a service. Hopefully someone can provide an answer to get it working as a service.

Download the installer setup-x86-64.exe and run it.

You need these packages:

  • cygrunsrv
  • openssh
  • openssl
  • rsync
  • xinit
  • xorg-docs
  • xorg-server

After Cygwin is installed, run the "Cygwin64 Terminal" as Administrator.

ssh-host-config

Should privilege separation be used? (yes/no) yes

new local account 'sshd'? (yes/no) yes

Do you want to install sshd as a service? (Say "no" if it is already installed as a service) (yes/no) no

Give your user ownership of their SSH directory:

chown username /var/empty /etc/ssh*

Edit the sshd configuration file:

vi /etc/sshd_config

Allow the SSH environment file to be used for non-interactive sessions:

PermitUserEnvironment yes

You need a login script to start sshd every time, I lazily created sshd.bat and copied it to shell:common startup

@echo off

REM # Start SSH server, as a regular process.  Use /var/log/sshd.log instead of
REM # Windows Event Log
C:\cygwin64\bin\run -p C:\cygwin64\bin /usr/sbin/sshd -D -E /var/log/sshd.log

Improvements welcome!