Windows ssh/git Server
If you are developing software and are using Git on Windows 10 and don't want to push to github, gitlab, etc., you might find this useful.
You can turn your Windows OS into a git server, by just configuring ssh access.
1. Add the features for OpenSSH (part of Windows 10)
Open Settings - Apps - Optional Features - Add a feature
and install "OpenSSH Server" and "OpenSSH client"
2. Create a git user
Create a user git, member of sshusers, who cannot change his password, who is active and whose password never expires.
Open Control Panel - Administrative Tools - Computer Management
Under System Tools - Local Users and Groups - Right click on Users - New User...
3. Configure the git user
Login with the git user and create the c:\Users\git\.ssh directory.
Inside, create the "authorized_keys" text file with your public ssh key and make it accessible only by user git.
Here is how to generate them if you don't have them yet (replace myuser with your username):
❕Important: Limit the access to your private key to your user only!
Leave the passphrase empty if you don't want to enter it on each git command.
Add the contents of id_rsa.pub to the previously mentioned authorized_keys.
4. Configure the git repositories directory
or add a sym link (shortcut) named "git", pointing to the desired location:
5. Configure the console client
By default, Windows uses its own console for SSH, which is really weird, when called from Unix/Linux devices. Fortunately, git comes with a bash console client for Windows and we can use it instead.
In the registry, under HKEY_LOCAL_MACHINE\SOFTWARE\OpenSSH, add String entry "DefaultShell" with value "C:\Program Files\Git\bin\bash.exe" (or wherever your git is installed).
Here is a reg file for this:
6. Configure the ssh daemon.
In sshd_config under C:\ProgramData\ssh\
Disable 2nd authorized_keys:
Allow access only to users from the group sshusers:
Disable password authentication (use only ssh keys):
7. Try SSH
8. Try Git
Create a repository in the git repository dir:
Try to clone it:
And let's push something: