Skip to content

Instantly share code, notes, and snippets.

@Locoxella
Last active December 14, 2023 11:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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"
@lxhom
Copy link

lxhom commented Nov 3, 2022

TYSM i was about to look up how to do the autostart myself :D

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