First of all, you'll need a working MinGW setup. Today, it means
downloading and running the installer of the awesome mingw-get:
http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get-inst/mingw-get-inst-20100909/mingw-get-inst-20100909.exe/download
Follow all the defaults. After you go through the installer, create a
shortcut to MinGW/msys/1.0/msys.bat shell startup script for your
convenience. After that, launch this shell, and execute:
sh /postinstall/pi.sh
Next, you need msysgit, to obtain the bleeding-edge, patched version
of openssh. Get it from:
https://code.google.com/p/msysgit/
Finally, the last auxiliary step you'll have to perform, is to set up
%Path% to include the path to the git binary for MinGW. To do this,
just copy the piece of %Path% added by the msysgit installer, and
change the last component in the copy from 'cmd' to 'bin'.
Now, on to building stuff. Launch the MinGW shell, and execute:
mingw-get install mingw-developer-toolkit msys-zlib-dev
which will download and install the MinGW DTK and zlib headers.
Next, download OpenSSL, and build it:
curl http://openssl.org/source/openssl-1.0.0a.tar.gz | tar xz
cd openssl-1.0.0a
./Configure --prefix=/mingw mingw no-capieng
make depend all install
Finally, obtain NoMachine's openssh sources with my 'secret sauce'
patches:
git clone git://git.feelingofgreen.ru/openssh
Then configure and build it:
cd openssh
export CPPFLAGS="-I/include -I$(PWD)/openbsd-compat -I$(PWD)/contrib/win32/win32compat/includes"
export LDFLAGS="-L/lib"
autoreconf
(
cat <<EOF
0000000: 3a31 3532 3933 0d61 7472 7565 1b3a 7771 :15293.atrue.:wq
0000010: 0d .
EOF
) | xxd -r > configure-fixup.vim
vim -s configure-fixup.vim configure
./configure --prefix=/
cat config.h.tail >> config.h
make ssh.exe sshd.exe
Finally, before installing it, edit sshdconfig, find the
"UsePrivilegeSeparation" commented out option, uncomment it and change
it to "no".
Now, copy things to their destination:
cp sshd.exe /bin
cp sshd_config /etc/ssh
cp /mingw/bin/libssp-0.dll /etc/ssh
You need to produce host keys somehow, and put them into /etc/ssh.
At this point you already can run sshd in the foreground, like this:
cd /etc/ssh
/bin/sshd -r
However, I presume you'd rather install it as a windows service.
To do this, you'll first need to install the Windows Resource Kit.
Get it from:
https://www.microsoft.com/downloads/en/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
We'll need just three executables out of the whole thing:
-
instsrv.exe
-
ntrights.exe
-
srvany.exe
Copy them into MinGW's /bin.
Now, you have to choose an account in the 'Administrators' group.
For the sake of simplicity, let's call it "user". Now execute:
reg add HKLM\\SYSTEM\\CurrentControlSet\\Services\\sshd\\Parameters //f //v Application //t REG_SZ //d c:\\mingw\\msys\\1.0\\bin\\sshd.exe
reg add HKLM\\SYSTEM\\CurrentControlSet\\Services\\sshd\\Parameters //f //v AppDirectory //t REG_SZ //d c:\\mingw\\msys\\1.0\\etc\\ssh
reg add HKLM\\SYSTEM\\CurrentControlSet\\Services\\sshd\\Parameters //f //v AppParameters //t REG_SZ //d "-r -M"
ntrights -u user +r SeLockMemoryPrivilege
ntrights -u user +r SeCreateTokenPrivilege
ntrights -u user +r SeAssignPrimaryTokenPrivilege
ntrights -u user +r SeServiceLogonRight
ntrights -u user +r SeIncreaseQuotaPrivilege
ntrights -u user +r SeTcbPrivilege
ntrights -u user +r SeImpersonatePrivilege
instsrv sshd c:\\mingw\\msys\\1.0\\bin\\srvany.exe
…while being mindful about your real MinGW install path.
Then, run msconfig, open the "Services" pane, find the "sshd"
service, and make it run as "user" (don't forget to enter the
password), not as "Local System".
Finally, ensure that the port 22 is open to outside connections in the
Windows Firewall – add a simple inbound rule for that port (not an
application!).
Having gone through all this, sshd can now be started like this:
sc start sshd