compile openssh
http://superuser.com/questions/965374/setup-ssh-in-background-windows
I was working on solution for this issue few months ago, because it was required for one project in my current job. The problem is described in openssh bugzilla, with attached patch that works around the missing cygwin feature. I was also discussing this with both upstream developers and cygwin maintainers, but it looks like it is not yet applied in any of these releases.
Short story long
Cygwin doesn’t have implemented one special messaging protocol which allows to pass file descriptors between completely unrelated processes on Unix. From words of cygwin maintainer, it looks like impossible to implement this feature in Windows API, since File descriptors are understood in totally different way.
I got this though from my friend who pointed out that this is quite common problem and I would make many people happy if this would work. So I started hacking and came up with this solution with sockets instead, which was successfully used in the above mentioned tool — scap-workbench.
How to get it?
That is the question. I thought that I should write some how-to build your ssh under cygwin, so this is great opportunity.
Build from source
Download and install cygwin from cygwin.com
From Cygwin repository install openssh and its dependencies (basically this list should be sufficient):
./setup-x86_64.exe -nq -P autoconf,automake,binutils,cygport,cygwin-devel,gcc-core,git,libcom_err-devel,libcom_err2,libcrypt-devel,libcrypt0,libedit-devel,libedit0,libgcc1,libgssapi_krb5_2,libiconv-devel,libiconv2,libintl-devel,libintl8,libk5crypto3,libkrb5-devel,libkrb5_3,libkrb5support0,libncurses-devel,libncursesw10,libopenssl100,libssp0-4.9.2-3,make,openssl-devel,w32api-headers,w32api-includes,zlib-devel,zlib0-1.2.8-3,git,wget
Reopen Cygwin terminal
Download latest released portable version (currently 7.1p1)
wget http://mirror.steadynet.cz/pub/OpenBSD/OpenSSH/portable/openssh-7.1p1.tar.gz # or you can choose different mirror
tar zxvf openssh-7.1p1.tar.gz
cd openssh-7.1p1
autoreconf
apply patch (I hope it applies still smooth)
wget https://raw.githubusercontent.com/Jakuje/stuff/master/openssh_without_fdpass.patch
cat openssh_without_fdpass.patch | patch
configure
mkdir build
cd build
../configure –prefix=/usr \
–sysconfdir=/etc \
–libexecdir=’${sbindir}’ \
–localstatedir=/var \
–datadir=’${prefix}/share’ \
–mandir=’${datadir}/man’ \
–infodir=’${datadir}/info’ \
–with-kerberos5 \
–with-libedit \
–with-xauth=/usr/bin/xauth \
–enable-etc-default-login
build it!
make CFLAGS=-g
Download ready binary with all dependencies
Available from fedorapeople.org
Urge upstream
Other possibility is to urge openssh or cygwin to apply this patch. This would make it helpful for more people. I didn’t make too much effort in this since I publishing the patch, because of other tasks.
Minimal test case
# initiate connection
SSH_HOST=”user@hostname”
C_PATH=”~/.ssh/master_%r@%h:%p.socket”
./ssh -M -f -N -o -p 314 ControlPath=”$C_PATH” “$SSH_HOST”
# do whatever commands you want
./ssh -o ControlPath=”$C_PATH” “$SSH_HOST” -p 314 “echo test”
# terminate connectino
./ssh -o ControlPath=”$C_PATH” “$SSH_HOST” -p 314 -O exit
(note ./ssh, because we want to invoke the binary which is built in the current directory and not the one provided by cygwin, which is in your $PATH)