Gitlab CI – SSH Into Virtual Private Server (VPS) Using Private Key From Gitlab CI Pipeline Job1 min read

Gitlab CI is a pain in the ass sometimes. It was a pain in my ass too.

I was stuck for more than 2 hours trying to figure out how to SSH into my own server with my own private key.

I tried so many things. And the shit becomes even more frustrating when the same piece of code works on your local but not on Gitlab CI.

In my case, it went a step further to test my sanity. I used the local docker alpine image which I was using in Gitlab CI, and it worked. But the same image with same commands didn’t work on Gitlab.

I know I felt like pulling my hairs off. But finally, with a few adjustments, I found in various places. I was able to piece it all together.

Here’s the code snippet that I’m not letting go for many years to come 😀

Please let me know if you are facing any trouble. I might point you in the right direction. And do not forget to subscribe 🙂

Just stay back and explore more in Programming.

  • Article By: Varun Shrivastava

  • Varun Shrivastava is an innovative Full Stack Developer at ThoughtWorks with around 4 years of experience in building enterprise software systems in finance and retail domain. Experienced in design, development, and deployment of scalable software. He is a passionate blogger and loves to write about philosophy, programming, tech and relationships. This is his space, you can get in touch with him here anytime you want.