If GIT provision are not already in place then a GIT server can easily be established. The example below shows the setup for a remote Linux Server (Ubuntu Server 20.04 LTS) and a local Linux Desktop (Xubuntu Desktop 20.04 LTS). The Server will be used to host the repositories and the Desktop used to access them.
Open up two terminals, one for the Desktop and one for the Server.
Create a new user on the Server called
git and create the SSH directory structure.
steve@Desktop:~$ ssh 192.168.2.20
steve@Server:~$ sudo useradd -r -m -U -d /home/git -s /bin/bash git
steve@Server:~$ sudo su - git
git@Server:~$ mkdir .ssh
git@Server:~$ chmod 0700 .ssh
git@Server:~$ touch .ssh/authorized_keys
git@Server:~$ chmod 0600 .ssh/authorized_keys
Check for the existence of a SSH key pair on the Desktop.
steve@Desktop:~$ cat .ssh/id_rsa.pub
If the return from the above is
No such file or directory then create a SSH key pair on the Desktop. Press enter at the key location prompt to use the suggested location. Enter a password at the passphase prompt and confirm this at the next passphase prompt.
steve@Desktop:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/steve/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
The key fingerprint is:
SHA256:0l/Upmt2lqfE81I72v5Zm5/mOR3L8/2Mr5Wjwi805Pg steve@Desktop
The key's randomart image is:
+---[RSA 4096]----+
| |
| . |
| . o |
| . o o |
| . S + o |
| . o = o oo|
| = = O+O|
| E ++^@|
| ++O&^|
+----[SHA256]-----+
Copy the already existing or newly generated
Public Key to the Server.
steve@Desktop:~$ scp ~/.ssh/id_rsa.pub steve@192.168.2.20:/home/steve
Add the copied
Public Key to the
Authorized Keys on the Server and then delete the copied
Public Key.
git@Server:~$ cat /home/steve/id_rsa.pub >> .ssh/authorized_keys
git@Server:~$ sudo rm /home/steve/id_rsa.pub
Perform a quick check to ensure that everything is working as expected.
Create an example repository on the Server.
git@Server:~$ git init --bare example.git
Setup GIT credentials on the Desktop.
steve@Desktop:~$ git config --global user.email your@email_address
steve@Desktop:~$ git config --global user.name "Your Name"
Clone the example repository on the Desktop, add a new file, commit the changes to the staging area and then push the changes back to the Server. Check status throughout.
steve@Desktop:~$ cd /tmp
steve@Desktop:/tmp$ git clone git@192.168.2.20:example.git
Cloning into 'example'...
warning: You appear to have cloned an empty repository.
steve@Desktop:/tmp$ cd example
steve@Desktop:/tmp/example$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
steve@Desktop:/tmp/example$ echo "Some wise words required..." > readme.txt
steve@Desktop:/tmp/example$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
readme.txt
nothing added to commit but untracked files present (use "git add" to track)
steve@Desktop:/tmp/example$ git add readme.txt
steve@Desktop:/tmp/example$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: readme.txt
steve@Desktop:/tmp/example$ git commit -m "Added readme file, alas no wise words yet!"
[master (root-commit) cac7986] Added readme file, alas no wise words yet!
1 file changed, 1 insertion(+)
create mode 100644 readme.txt
steve@Desktop:/tmp/example$ git status
On branch master
Your branch is based on 'origin/master', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
nothing to commit, working tree clean
steve@Desktop:/tmp/example$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 258 bytes | 258.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To 192.168.2.20:example.git
* [new branch] master -> master
steve@Desktop:/tmp/example$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
Clone the repository again, this time into a named directory. Check the new file does indeed exist.
steve@Desktop:/tmp/example$ cd ..
steve@Desktop:/tmp$ git clone git@192.168.2.20:example.git example_check
Cloning into 'example_check'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
steve@Desktop:/tmp$ cd example_check
steve@Desktop:/tmp/example_check$ cat readme.txt
Some wise words required...
steve@Desktop:/tmp/example_check$ git log
commit cac798667af67d2ed245672cb36a786f0c3208ed (HEAD -> master, origin/master, origin/HEAD)
Author: Steve <steve@Desktop>
Date: Thu Dec 30 12:24:54 2021 +0000
Added readme file, alas no wise words yet!