Admins and Developers Guide to Manage your Scripts & Files
Please support my articles by clicking on the CLAP button. It doesn’t cost you anything to clap.
The Easy way to Setup your Home or Office Git Server
Introduction

Whether you work as a developer or a writer or you have a team or tasks of working editing and reviewing documents and files then you need a document versioning control solution we call it GIT.
You can imagine the kind of chaos you will go through if various versions are stored at various locations. It would lead to further trouble if the latest version is missed out to even one concerned person who might possibly use the document.
If you accidentally delete a file, you can automatically undo it. If you have multiple users can make the changes simultaneously from various.
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.[git-scm website]

Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development.[wikipedia]
Today, I will guide you on how to set up your private Git Server on a Linux System.
For the purpose of demonstration, I created two virtual machines one will be my Git Server which will host all my repository commits etc and the other one will be my client system where I will be developing and pushing my codes from.
Git Server: gitserver.local.domain
Client System: client.local.domain
Note: You can have as many clients or systems as you need in our case it was one system for demonstration.
What About Windows and MacOS
Please note git can be also installed on Windows and MacOS. Git commands line can be run using Windows Powershell or you could use any available git GUI client from the opensource community. Git packages can be downloaded from http://git-scm.com/download/win.
Setting up ssh key authentication from a Windows system to Linux is a little bit different. You can use a free tool such as PUTTYGEN to generate your ssh keys. To download PuTTY or PuTTYgen, go to http://www.putty.org/
PUTTY is used to access ssh shell from a windows system. To generate ssh keys on Windows follow these steps:
- Run the PuTTYgen program.
- The PuTTY Key Generator window is displayed.
- Set the Type of key to generate an option to SSH-2 RSA.
- In the Number of bits in a generated key box, enter 2048.
- Click Generate to generate a public/private key pair.
- As the key is being generated, move the mouse around the blank area as directed.
- (Optional) Enter a passphrase for the private key in the Key passphrase box and reenter it in the Confirm passphrase box.
- Click save your private keys and public keys to file then copy the contents of the public key to the git server
- Open Putty and Configure SSH option to point to the private key file
MacOS git setup is a straightforward process. The packages can be downloaded from https://git-scm.com/download/mac.
The command line can be accessed from the macOS terminal.
Generating ssh keys and creating accounts on macOS is similar to Linux and can be done from the terminal.
The Setup
Step 1 Install git and edit hosts file on both Client System and the Git server
> yum install git -y> vi /etc/hosts10.131.92.196 gitserver.local.domain gitserver
10.131.92.195 client.local.domain client
save the file wq!
“Note: Your IP addresses and hostnames can be different than mine”
Step 2 Create a user account on the Git Server to use with our repositories
> useradd git
Step 3 Switch to the newly created user account and create an empty repository, then list the contents of the folder.
> su git
> cd
> mkdir -p gitdata
> cd gitdata
> git init --bare
Initialized empty Git repository in /home/git/gitdata> ls
branches config description HEAD hooks info objects refs
Step 4 While you in the git user session, create the ssh folder then generate the ssh keys for the git user on the Git Server
> mkdir .ssh && chmod 700 .ssh
> touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
Step 5 Now, on the Client system, create the user jdoe, then generate the ssh keys for the account
> useradd jdoe
> su jdoe
> cd
> ssh-keygen -t rsa Generating public/private rsa key pair.
Enter file in which to save the key (/home/jdoe/.ssh/id_rsa):
Created directory '/home/jdoe/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jdoe/.ssh/id_rsa.
Your public key has been saved in /home/jdoe/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:0AuYW2upQBgOlWhw6PQ7PHAoLi4vRoyHcal90Ceryy0 jdoe@client.local.domain
The key's randomart image is:
+---[RSA 2048]----+
|=+o. |
|=*. o . |
|=.+oo + . |
|o=+ooo.= . |
|=*=.o++ S |
|=+o*oo |
|+. o+ |
|o+E. |
|oo+o. |
+----[SHA256]-----+> cd .ssh
> cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCWP3u09b1VbdY65LGIHfUikC/ccB/tztGzHEw7JHEo zfiXcKj4zk5ViyLxBVRcKW0nkB6Hw5lsDIFkbWMdGPPtyNs+QrFt0McjVhgY9e8B3Urvclk6DRPeBxkq 5qfqwQOKdgpZ5/6WG2LVPONvAhTDjPpWyLnvJ8JZh8px8nr9bidQoTe5MVwlnBpPL31JRVbBD3mEmAyk nRenp6AmWiTBWTLDk5TT8JCq2+P9L0I0IWb5n5+NVwWmzgCFBoJ8uBhaQMTl0FRWbli7qZHRyPaV3gdk hAvGNCnERIAqlgw6r/ik+SkRV7Iq7URiFWHbu9OLhh7cnC2+roTGPbAGeirT jdoe@client.local.d omain
Step 6 Add the ssh keys for jdoe to the authorized keys file on the Git Server
> vi .ssh/authorized_keysssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCWP3u09b1VbdY65LGIHfUikC/ccB/tztGzHEw7JHEozfiXcKj4zk5ViyLxBVRcKW0nkB6Hw5lsDIFkbWMdGPPtyNs+QrFt0McjVhgY9e8B3Urvclk6DRPeBxkq5qfqwQOKdgpZ5/6WG2LVPONvAhTDjPpWyLnvJ8JZh8px8nr9bidQoTe5MVwlnBpPL31JRVbBD3mEmAyknRenp6AmWiTBWTLDk5TT8JCq2+P9L0I0IWb5n5+NVwWmzgCFBoJ8uBhaQMTl0FRWbli7qZHRyPaV3gdkhAvGNCnERIAqlgw6r/ik+SkRV7Iq7URiFWHbu9OLhh7cnC2+roTGPbAGeirT jdoe@client.local.domain
Save the file wq!
Step 7 Try to ssh from the Client System to the Git Server to test your key authentication login
> ssh git@gitserver.local.domain
Enter passphrase for key ‘/home/jdoe/.ssh/id_rsa’:
Last login: Mon Oct 22 11:11:36 2018
Excellent!
Step 8 Configure git config file on the Client System
> vi .gitconfig
[user]
name = JOHN DOE
email = jdoe@client.local.domain
Save the file wq!
Step 9 On the Client System create a file or folder while logged in as jdoe , and push to the Git Server
> mkdir project1
> cd project1
> echo "this is my git project file" > projectfile.txt> git init
Initialized empty Git repository in /home/jdoe/project1/.git/> git commit -m 'Initial Commit'
[master (root-commit) e39ddbe] Initial Commit
1 file changed, 1 insertion(+)
create mode 100644 projectfile.txt> git remote add origin git@gitserver.local.domain:gitdata> git push origin masterEnter passphrase for key '/home/jdoe/.ssh/id_rsa':
Counting objects: 3, done.
Writing objects: 100% (3/3), 247 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@gitserver.local.domain:gitdata
* [new branch] master -> master
This is how my config file under .git folder looks like.
> cat .git/config[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote “origin”]
url = git@gitserver.local.domain:gitdata
fetch = +refs/heads/*:refs/remotes/origin/*
Step 10 Other Users Can Clone project 1 file, let's create a different account under the Client System, generate the keys, move the keys to GitServer then attempt to clone.
> useradd sara > ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/sara/.ssh/id_rsa):
Created directory '/home/sara/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/sara/.ssh/id_rsa.
Your public key has been saved in /home/sara/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:y+Z6+kh56raDMsztu5NoavS5OnQVJk20z27aG5q8n6A sara@client.local.domain
The key's randomart image is:
+---[RSA 2048]----+
| +o |
| . +. |
| o.. |
| .o |
| . oS |
| o . .o . |
|oooo.+o+= |
| oBoB.X*+ |
|o+oE=%X%+ |
+----[SHA256]-----+> cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTqih0FGHhcNMqMEJPI9oKmwveBTvxIg4DwYqhJp/uV3EygMj66OTb8mB05C4fRMRlPuagCCLgroaNt8/ylW3qAI2n+/sJNJmOuZCT0O850B0l3/zpHwdmjzFFXrqSqTAI4RxFR3Y1oKSOJ4YgxDq6sb0CtPP2HZVtwR08PPmQo6n8f6y8nw0Nk06hAdEH7RScD0CSu9pSiP+d/gzhPG4dlvKPnriOAxHtcO7a1+3ly2+mefAXSrZHrJkvDQdpPynemZWUa56sEXmQaG4ZFtpx5mXbmV0ckZ+nt4vHIJE+npTDSxEwyiVfksPupFfUpcoH6RdGHLknh3FDTJKPPNhz sara@client.local.domain
Step 11 Append the contents of the public key to the Git Server authorized_keys file then test from the Client System terminal that you have access to the Git Server
> vi .ssh/authorized_keys...
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTqih0FGHhcNMqMEJPI9oKmwveBTvxIg4DwYqhJp/uV3EygMj66OTb8mB05C4fRMRlPuagCCLgroaNt8/ylW3qAI2n+/sJNJmOuZCT0O850B0l3/zpHwdmjzFFXrqSqTAI4RxFR3Y1oKSOJ4YgxDq6sb0CtPP2HZVtwR08PPmQo6n8f6y8nw0Nk06hAdEH7RScD0CSu9pSiP+d/gzhPG4dlvKPnriOAxHtcO7a1+3ly2+mefAXSrZHrJkvDQdpPynemZWUa56sEXmQaG4ZFtpx5mXbmV0ckZ+nt4vHIJE+npTDSxEwyiVfksPupFfUpcoH6RdGHLknh3FDTJKPPNhz sara@client.local.domain> ssh git@gitserver.local.domain
The authenticity of host ‘gitserver.local.domain (10.131.92.196)’ can’t be established.
ECDSA key fingerprint is SHA256:thRRmC+M31SYsBOp+gSPiwoe81nkVwPmUCVMYVJG5Dg.
ECDSA key fingerprint is MD5:98:d1:08:0f:10:58:ab:e0:9b:81:f3:d5:46:5d:62:42.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘gitserver.local.domain,10.131.92.196’ (ECDSA) to the list of known hosts.
Enter passphrase for key ‘/home/sara/.ssh/id_rsa’:
Last login: Mon Oct 22 11:50:51 2018
[git@gitserver ~]$ exit
logout
Connection to gitserver.local.domain closed.
[sara@client .ssh]$
At this point lets clone the repository
> git clone git@gitserver.local.domain:gitdata
Cloning into 'gitdata'...
Enter passphrase for key '/home/sara/.ssh/id_rsa':
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
> ls
gitdata> vi .gitconfig[user]
name = SARA ANDERSON
email = sara@client.local.domain> cd gitdata/
> ls
projectfile.txt
> cat projectfile.txt
this is my git project file
Let’s add more texts to the projectfile.txt
> vi projectfile.txt
this is my git project file
#
We need to add more text files to this project
We need a road map to plan.
Save the file wq!
> git commit -am ' Instructions Added'
[master f73b292] Instructions Added
1 file changed, 4 insertions(+)> git push origin masterEnter passphrase for key '/home/sara/.ssh/id_rsa':
Counting objects: 5, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 342 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@gitserver.local.domain:gitdata
e39ddbe..f73b292 master -> master> git log
commit f73b29290b48e1b40cb5eacbd37ad5539a8b3d46
Author: SARA ANDERSON <sara@client.local.domain>
Date: Mon Oct 22 12:04:20 2018 +0000
Instructions Addedcommit e39ddbec3f2def4d80360483b13fc02e1e148572
Author: John Doe <jdoe@client.local.domain>
Date: Mon Oct 22 11:24:55 2018 +0000Initial Commit
Bonus
You can make your git commits more readable and colorful by editing your .gitconfig file for your users or create a global file for all your users by appending the following :
> vi .gitconfig......[color]
diff = auto
interactive = auto
ui = truepager = true[color "status"]
added = green
changed = red bold
untracked = magenta bold[color "branch"]
remote = yellow
save the file wq!
Running git log command again we get the following:

I have Windows though
If you have Windows users no problem. Download the git windows client app from https://git-scm.com/downloads
Last Words
In this article, we explained step by step how to set up your git-server and a git-client to take advantage of this great tool using SSH authentication.
The negative aspect of SSH is that it doesn’t support anonymous access to your Git repository. If you’re using SSH, people must have SSH access to your machine, even in a read-only capacity, which doesn’t make SSH conducive to open source projects for which people might simply want to clone your repository to examine it.[source:gitscm]
Git is a great tool at your disposal if you want to learn more about the tool and how to efficiently use it in your environment check the git-scm website at https://git-scm.com/book/en/v2 and https://onlywei.github.io/explain-git-with-d3/#freeplay.
If you have questions or interested in providing feedback please comment below.
Disclaimer
Although he information on this article is composed and maintained with continuous care and attention, I , the author cannot give any warranty as to the correctness or completeness of the information on this website. The information is furthermore not intended as any other professional and personal advice in any way. The consequences of decisions, solely based on the information on this website, remain at one’s own risk. The author is therefore under no circumstances liable for damages of whatever nature, in anyway resulting from or related to the use of information presented on or made available through this website.The article includes references and hyperlinks to third party websites, which are not controlled by Author. These references and hyperlinks are included for information purposes only. In no event Author gives any guarantee or accepts any liability in relation to the content, use and accessibility of such websites.