SSH connection to AWS from Gitlab CI

preview_player
Показать описание
In this tutorial, I will show you how to establish an SSH connection from a Gitlab CI server to another server. It is not necessary for the other server to have the Gitlab CI runner installed.

The ssh command includes the StrictHostKeyChecking flag. If this flag is set to no, the ssh client will automatically add host keys to the ~/.ssh/known_hosts file and will accept to connect to hosts whose host key has changed. This is why we create the .ssh folder and set the right permission to it.

Resources:

Using SSH keys with GitLab CI/CD -

___

// GitLab CI/CD ONLINE COURSE

👉 Want to learn more about CI/CD pipelines? Check my GitLab CI online course.

Get it at a special price and help support this YouTube channel:

___

// I HAVE A QUESTION!

I do my best to answer all comments here on YouTube but I cannot make any guarantees.

___

// I HAVE A VIDEO IDEA

Do you want me to create a video on a specific topic? Just fill out the form below:

___

// P L A Y L I S T S

___

// F R E E R E S O U R C E S

▸▸▸ Official Gitlab CI documentation

▸▸▸ 👉 Subscribe to the "Testing and automation with Valentine" newsletter for bi-weekly tutorials, tips, and news from the industry.

___

// YOUR SUPPORT ON PATREON MATTERS

If you enjoy this content, help me create more like this. Consider supporting me on Patreon.

___

// IMPRINT

---
Рекомендации по теме
Комментарии
Автор

👉 Want to learn more about CI/CD and DevOps? Check my Gitlab CI online course.

vdespa
Автор

A really great video. Exactly what I was looking for.
Is it safe to use put contents from .pem file into a variable without masking it? GitLab does not allow me to mask the variable.

mykolaskucinskas
Автор

Another amazing tutorial @valentin. Thanks!!
I have got one quick ask. lets say instead of having two commands touch and unzip in single job/stage can we have them separately in different jobs/stages? in such scenario will ssh command need to run for each job/stage ? OR the ssh connection established at first job/stage will be available to second job/stage as well ?? can you please help me with such example pipeline ?? Thanks!!

shishirpandey
Автор

At 2:53 which key is that is it the ssh key of my remote server on which i want to deploy my code? I am getting enter Passphrase error, however i cannot use a key without a passphrase, is there any workaround?

Rohitsingh
Автор

Thank you for this video, it was clear and good

opusdei
Автор

Thanks for this video! It's so useful and clear.

abrahanzarza
Автор

Thanks for this vid, I have a question, is it possible to port the "before script" in windows without the Docker?

Zefr
Автор

Thanks for the video and i have a question, If i want to deploy from gitlab to testing server(not in aws ..own server) using ci/cd whar is the steps to follow.

satyasai
Автор

Hi Valentin, great content I love your videos, tell me is this possible to use ssh key to clone from another private project?

dawidpolakowski
Автор

Is the "-s" required for ssh-agent ? The man says the default output is already for Bash and normal shell.

AlessandroPiccione
Автор

Hi Valentin, I'm facing a issue that "[my-domain] port 22: Operation timed out" or "Permission denied (publickey)". Hence could I know any security I need to setup for the gitlab-ci to access the aws via SSH? thanks so much, your tutorial is so useful to me.

However, I can use the ssh -i [pem file] [user]@[DNS] to access the server.

benhopakcheungben
Автор

Can you please tell which EC2 instance have you used ? linux or ubuntu! Since my gitlab deploy is passed but on putting the ip address the page is not there

vanshikasharma
Автор

How to deploy the same if machine is behind the bastion host. My aws instance is behind bastion which I finding it difficult to run task which I tried like tricky way like adding SSH/conf in the runner but didnt work can u please suggest if any way to do so.

keerthirajasj
Автор

Hi, what if I don't want to use alpine image, I just want to deploy my react app on a shared runner using docker node.js image. Can I use the before_script here?

RahulYadav-nkwp
Автор

Your video is useful. I am stuck at security group point. If i allow ssh port on my server side open, i am able to deploy from gitlab.
once i restrict with specific IP to ssh, i could not deploy from gitlab. is there any specific IP for gitlab to whitelist and add on my ec2 server security group?

Thanks in advance..

abduljaleel
Автор

Hi Valentin, how to deploy multiple VMs? And store the list of VMs on variable

amrukarim
Автор

Im new to this.
Can I technically configure a .gitlab-ci.yml file in a way that whenever I save changes to a repository (so after every commit) on GitLab that all the files in the repository are sent to an ssh server I use. Then it gets compiled via predefined commands on a Linux machine. And then the executable compiled file gets saved to the repository in a new folder.

So basically if I create a Helloworld.c file in C. After I commit it to the GitLab repository it should be sent to a Linux ssh server. Get compiled and also added to the repository

I just want a yes or no. If this work I will figure it out myself. Thanks :)

martinsauer
Автор

how have u setted the private key n from where?

anampatel
Автор

Can you show us how to make it with the default ssh executor runner

anoj
Автор

As I know GitLab does not still have a way to share the image between the stages.
In my case I noticed I can save a full minute just using the same stage for build and deploy. It is perfectly fine especially when the image is the same like in this case ("alpine").

AlessandroPiccione
join shbcf.ru