@echo off setlocal rem Gather info from user set /P account="Enter the domain user that will log in to SSH: " set /P passwd="Enter %account%'s password: " cls rem Install CygWin "%~dp0cygwin_setup.exe" -q -L -n -l "%~dp0Packages" rem Set the CygWin variable on the system for future use setx CYGWIN "binmode ntsec" /M rem Set the variable locally so we can use it in the current session set CYGWIN=binmode ntsec rem Echo the commands we need to execute in CygWin to set up SSH :CYGWIN_CONFIG set cygwin_input=%TEMP%\cygwin_input.txt echo cygrunsrv -h> %cygwin_input% rem echo editrights -u %account% -a SeAssignPrimaryTokenPrivilege>> %cygwin_input% rem echo editrights -u %account% -a SeCreateTokenPrivilege>> %cygwin_input% rem echo editrights -u %account% -a SeTcbPrivilege>> %cygwin_input% rem echo editrights -u %account% -a SeServiceLogonRight>> %cygwin_input% echo echo yes^> ssh_input.txt>> %cygwin_input% echo echo yes^>^> ssh_input.txt>> %cygwin_input% echo echo yes^>^> ssh_input.txt>> %cygwin_input% echo echo binmode ntsec^>^> ssh_input.txt>> %cygwin_input% echo echo no^>^> ssh_input.txt>> %cygwin_input% echo echo yes^>^> ssh_input.txt>> %cygwin_input% echo echo Garb@g3^>^> ssh_input.txt>> %cygwin_input% echo echo Garb@g3^>^> ssh_input.txt>> %cygwin_input% echo ssh-host-config ^< ssh_input.txt>> %cygwin_input% echo rm ssh_input.txt>> %cygwin_input% echo sed -i.bak '/%account%/d' /etc/passwd>> %cygwin_input% echo mkpasswd -d -u %account% ^>^> /etc/passwd>> %cygwin_input% echo mkdir -p %account% /home/%account%>> %cygwin_input% echo chown %account% /home/%account%>> %cygwin_input% rem Run CygWin and feed it our input file to set up SSH call C:\cygwin\cygwin.bat < %cygwin_input% rem Configure the service in Windows sc config sshd obj= PCC\%account% password= "%passwd%" rem Echo some additional commands to run in CygWin echo chown %account% /var/log/sshd.log> %cygwin_input% echo chown -R %account% /var/empty>> %cygwin_input% echo chown %account% /etc/ssh*>> %cygwin_input% echo chmod 755 /var/empty>> %cygwin_input% echo chmod 644 /var/log/sshd.log>> %cygwin_input% call C:\cygwin\cygwin.bat < %cygwin_input% rem And finally start the service and clean up net start sshd del %cygwin_input%