Gitlab Deploy though SSH

1.) Generate an SSH Key Locally (or Use an Existing One)

Run the following command in your local terminal to generate a new SSH key:

ssh-keygen -t rsa -b 4096 -C “your_email@example.com”

Simply press Enter through the prompts to a…


This content originally appeared on DEV Community and was authored by Booranasak Kanthong

1.) Generate an SSH Key Locally (or Use an Existing One)

Run the following command in your local terminal to generate a new SSH key:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Simply press Enter through the prompts to accept the defaults and create the key pair.

2.) Add the Public Key to the VM Server

On your VM server, append the contents of the generated public key (typically located at ~/.ssh/id_rsa.pub) to the authorized_keys file:

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

3.) Add the Private Key to Your GitLab Repository

To allow GitLab CI/CD jobs to connect to your VM via SSH:

3.1) Go to your GitLab repository.
3.2) Navigate to Settings → CI/CD → Variables.
3.3) Click "Add variable".
3.4) Set the key (e.g., SSH_PRIVATE_KEY) and paste your private key (from ~/.ssh/id_rsa) as the value.
3.5) Make sure to mask and protect the variable as appropriate.

Never share your private key. Treat it like a password.


This content originally appeared on DEV Community and was authored by Booranasak Kanthong


Print Share Comment Cite Upload Translate Updates
APA

Booranasak Kanthong | Sciencx (2025-07-20T11:28:41+00:00) Gitlab Deploy though SSH. Retrieved from https://www.scien.cx/2025/07/20/gitlab-deploy-though-ssh/

MLA
" » Gitlab Deploy though SSH." Booranasak Kanthong | Sciencx - Sunday July 20, 2025, https://www.scien.cx/2025/07/20/gitlab-deploy-though-ssh/
HARVARD
Booranasak Kanthong | Sciencx Sunday July 20, 2025 » Gitlab Deploy though SSH., viewed ,<https://www.scien.cx/2025/07/20/gitlab-deploy-though-ssh/>
VANCOUVER
Booranasak Kanthong | Sciencx - » Gitlab Deploy though SSH. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/20/gitlab-deploy-though-ssh/
CHICAGO
" » Gitlab Deploy though SSH." Booranasak Kanthong | Sciencx - Accessed . https://www.scien.cx/2025/07/20/gitlab-deploy-though-ssh/
IEEE
" » Gitlab Deploy though SSH." Booranasak Kanthong | Sciencx [Online]. Available: https://www.scien.cx/2025/07/20/gitlab-deploy-though-ssh/. [Accessed: ]
rf:citation
» Gitlab Deploy though SSH | Booranasak Kanthong | Sciencx | https://www.scien.cx/2025/07/20/gitlab-deploy-though-ssh/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.