Skip to content

Instantly share code, notes, and snippets.

@Locoxella
Last active September 26, 2024 06:45
Show Gist options
  • Save Locoxella/651f425b08428935ef251a72bdd0fc6a to your computer and use it in GitHub Desktop.
Save Locoxella/651f425b08428935ef251a72bdd0fc6a to your computer and use it in GitHub Desktop.
Enable sshd on MinGW
#!/bin/bash
#
# Configure sshd on MinGW for Windows
# Create host keys
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa
ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
# Configure sshd for password authentication with no user privilege authentication
sed -i '/UsePrivilegeSeparation /c\UsePrivilegeSeparation no' /etc/ssh/sshd_config
sed -i '/PasswordAuthentication /c\PasswordAuthentication yes' /etc/ssh/sshd_config
/usr/bin/sshd && echo "sshd is running" || { echo 1>&2 "Can't execute sshd, exiting without configuring windows"; exit 1; }
# Schedule sshd to start on boot and creates firewall rule for it on port 22
schtasks //CREATE //SC onstart //TN "mingw-sshd" //TR $(CYGPATH -w `which sshd`) //F
netsh advfirewall firewall delete rule name="mingw-sshd"
netsh advfirewall firewall add rule name="mingw-sshd" protocol=tcp localport=22 dir=in enable=yes action=allow
echo "sshd was configured properly to start on boot"
@klochowicz
Copy link

very useful, cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment