Skip to content

Instantly share code, notes, and snippets.

@rescenic
Forked from snallami/configuire.cmd
Created May 28, 2020 16:46
Show Gist options
  • Save rescenic/773802a66378b9835ddd713e3fabdc10 to your computer and use it in GitHub Desktop.
Save rescenic/773802a66378b9835ddd713e3fabdc10 to your computer and use it in GitHub Desktop.
Reconfigure cygwin
rem This script reconfigures the Cygwin sshd service.
rem It regenerates the computer's host keys. This is necessary
rem when Sysprep is run and a new SID is generated.
@echo off
echo Stopping the Cygwin sshd service...
net stop sshd
echo ERRORLEVEL: %ERRORLEVEL%
echo.
echo Deleting old "passwd" and "group" files...
del /q c:\cygwin64\etc\group
del /q c:\cygwin64\etc\passwd
c:\cygwin64\bin\sleep.exe 1
echo.
echo Creating new "group" file...
c:\cygwin64\bin\mkgroup.exe -l > c:\cygwin64\etc\group
echo.
echo Creating new "passwd" file and changing root's primary group from 'None' to 'Administrators'
c:\cygwin64\bin\mkpasswd.exe -l | c:\cygwin64\bin\sed.exe -e 's/\(^root.*:\)513\(:.*\)/\1544\2/' > c:\cygwin64\etc\passwd
echo ERRORLEVEL: %ERRORLEVEL%
echo.
echo Restoring ownership of files...
c:\cygwin64\bin\chown.exe -v root:None /etc/ssh*
c:\cygwin64\bin\chown.exe -v -R root:None /home/
c:\cygwin64\bin\chown.exe -v root:None /var/empty
c:\cygwin64\bin\chown.exe -v root:None /var/log/sshd.log
c:\cygwin64\bin\chown.exe -v root:None /var/log/lastlog
c:\cygwin64\bin\sleep.exe 2
echo.
echo Delete old SSH keys...
del /q c:\cygwin64\etc\ssh_host_*
echo.
echo Regenerating SSH keys...
c:\cygwin64\bin\ssh-keygen.exe -t rsa1 -f /etc/ssh_host_key -N ""
c:\cygwin64\bin\ssh-keygen.exe -t rsa -f /etc/ssh_host_rsa_key -N ""
c:\cygwin64\bin\ssh-keygen.exe -t dsa -f /etc/ssh_host_dsa_key -N ""
c:\cygwin64\bin\sleep.exe 1
echo.
echo Setting sshd service startup mode to auto...
"%SystemRoot%\System32\sc.exe" config sshd start= auto
echo ERRORLEVEL: %ERRORLEVEL%
echo.
echo Starting the Cygwin sshd service...
net start sshd
echo ERRORLEVEL: %ERRORLEVEL%
exit /B %ERRORLEVEL%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment