Wednesday, August 7, 2013

WinSCP and Cygwin


Most people believe Cygwin will not work with WinSCP.

I am not a fan of believing something will not work, so I setup "Custom Commands" in WinSCP to startup Cygwin mintty terminals.

SSH KEYS

First of all you should have ssh keys to allow auto login to server.
With the following Custom command added to WinSCP you can auto add an ssh key. I setup this command with hotkey Ctrl+0.

C:\cygwin\bin\mintty.exe /bin/bash -ile /cygdrive/c/Dropbox/WinSCP/ssh.sh !U !@ !P
 This is the ssh.sh script.

echo "USE THIS PASSWORD: $3"
cat /.ssh/id_dsa.pub | ssh $1@$2 'cat - >>~/.ssh/authorized_keys2'
 Which will echo the password for entry via WinSCP and allow you to setup your ssh key on the server you are connected to.

STARTING A CYGWIN TERMINAL (Mintty)


Now you need a command to launch Cygwin mintty.exe and log you into that server. This command I setup with hotkey Ctrl+1, which is very easy to use.

C:\cygwin\bin\mintty.exe /bin/ssh !U@!@

SSHPASS

And that is all you need to use Cygwin with WinSCP.
If you really wanted to you could avoid ssh keys by installing sshpass into Cygwin.

I created another file, sshpass.sh like this.
/usr/local/bin/sshpass.exe -p '$3' ssh $1@$2
And added the Custom Command pointed at that bash script. I setup this command with hotkey Ctrl+2.

C:\cygwin\bin\mintty.exe /bin/bash -ile /cygdrive/c/Dropbox/WinSCP/sshpass.sh !U !@ !P