First SSH into your server:
ssh username@domain.com -p 7822 (the 7822 is the port number and may be different on your server)
Go to the directory when you want to have the GitLab repo deployed to. Next get the GitLab ssh url from the GibLab project it will be like git@gitlab.com:username/project.git
To clone the repo type
git clone git@gitlab.com:username/project.git
On the first time you may get this warning:
The authenticity of host 'gitlab.com (52.167.219.168)' can't be established.
RSA key fingerprint is b6:03:0e:39:97:9e:d0:e7:24:ce:a3:77:3e:01:42:09.
Are you sure you want to continue connecting (yes/no)?
Enter yes, next you will get:
Warning: Permanently added 'gitlab.com,52.167.219.168' (RSA) to the list of known hosts.
Connection closed by 52.167.219.168
fatal: The remote end hung up unexpectedly
Now trying to do a git clone again results in the error:
Initialized empty Git repository in /home/username/public_html/project/.git/
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
The reason for this is the server has not been authenticated again.
To get setup follow these steps:
type
ssh-keygen
The output:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/mvc/.ssh/id_rsa):
Press enter to accept the default path
Enter passphrase (empty for no passphrase):
Press enter to accept no password or enter a password first.
The response will look something like:
The key's randomart image is:
+--[ RSA 2048]----+
| .. . .oB|
| . .. + .++|
| . o. o...|
| o . |
| S .. . |
| o. o |
| o..+ |
| ....o |
| oE. |
+-----------------+
Go to .ssh folder
cd ~/.ssh
cat id_rsa.pub
Copy the full key.
On Gitlab go to Settings -> Repository -> Deploy Keys
Add a title this is a reference so it can be anything then copy the key into the key box.
Now you should be all set up so once again go to where you want the repo to be pulled into and again type
git clone git@gitlab.com:username/project.git
the output will be:
initialized empty Git repository in /home/username/public_html/project/.git/
remote: Counting objects: 3048, done.
remote: Compressing objects: 100% (2125/2125), done.
remote: Total 3048 (delta 688), reused 2994 (delta 648)
Receiving objects: 100% (3048/3048), 9.83 MiB | 5.81 MiB/s, done.
Resolving deltas: 100% (688/688), done.
This will create a directory and pull in the repo contents.
Now anytime you want to update go into the directory and type
git pull