Last active
November 8, 2021 13:55
-
-
Save emha69/1332672a37038ffd40f719c41ea79050 to your computer and use it in GitHub Desktop.
Local Git Server setup in 10 steps with Ubuntu server and Windows clients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1. Setup Ubuntu 20.04 Linux server | |
Step 2. Install software on Windows client(s) | |
Step 3. Create SSH keys on the clients and copy to server | |
Step 4. Create remote repository | |
Step 5. Tweak Git to use SSH | |
Step 6. Create local repository | |
Step 7. Push it to the remote | |
Step 8. Clone to the clients | |
Step 9. Setup GitHub Desktop client | |
Step 10. Test it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Step 1. Basic setup Ubuntu 20.04 server
1. First check if Git is installed
git --version
2. If not, install Git with
sudo apt-get update
sudo apt-get install git
3. Add git user
adduser git
4. Change to git user and create folders
cd /home/git
mkdir ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
Create additional
temp
folder, which will be used later for file upload.Step 2. Install software on windows
https://github.com/git-for-windows/git/releases/
For now install with default options.
Step 3. Generate SSH keys on Windows 10
Press Win+R and open CMD for the current user
Generate private and public SSH keys
ssh-keygen
Save the
id_rsa
in .ssh folder under current user's home directory e.g.C:\users\$user\.ssh
Enter password to protect the private key.
The
id_rsa
andid_rsa.pub
keys will be created in theC:\users\$user\.ssh
folderCopy the
id_rsa.pub
file to the serverscp id_rsa.pub git@<host>:/home/git/temp/<user>.pub
Log in as git user to the server and add the key to the authorized keys
ssh git@<host>
cd temp
cat <user>.pub >> ../.ssh/authorized_keys
Logout from server and try to log in directly, using:
ssh git
Step 4. Create and init remote repository
ssh git@<host>
mkdir projects.git
cd projects.git
git init --bare
cd ..
chown -R git.git projects.git
Step 5. Tweak git on windows to use Windows SSH
Open Git bash console and enter:
git config --global core.sshcommand "C:/Windows/System32/OpenSSH/ssh.exe -i C:/users/$user/.ssh/id_rsa
Step 6. Create local repository on Windows PC
c:\Works\project
If this is an empty project create some dummy files:
touch file.c
touch file.h
git init
git add file.*
git commit -m "Initial commit
Step 7. Configure remote server and push to the remote repository
git remote add origin ssh://git@<host>:/home/git/project.git
git remote -v
git push origin master
Step 8. Clone to other Windows clients
git clone git@<host>:projects.git .
Step 9. Setup GitHub Desktop application
Step 10. Test it