SSH and GPG Keys With Gitpod

dtan13

Dhananjay Tanpure

Posted on December 27, 2021

SSH and GPG Keys With Gitpod

Get Your .gitconfig

  1. Your Git Config is located at ~/.gitconfig
  2. Encode the File with base64:
cat .gitconfig | base64 -w 0
Enter fullscreen mode Exit fullscreen mode
  1. Create a variable on gitpod.
  • Enter Name GITCONFIG.
  • Enter output of previous command as Value.
  1. Add following task to your .gitpod.yml:
tasks:
    - before: >
          [[ ! -z $GITCONFIG  ]] &&
          echo $GITCONFIG | base64 -d > ~/.gitconfig &&
          chmod 644 ~/.gitconfig
Enter fullscreen mode Exit fullscreen mode

Make commits GPG-signed

  1. To sign commit using GPG you must first add GPG keys to Github and/or Gitlab.
  1. Your GPG Keys are stored in ~/.gnupg folder. Encode this folder with base64.
tar -czf - ~/.gnupg | base64 -w 0
Enter fullscreen mode Exit fullscreen mode
  1. Create a variable on gitpod.
    • Enter Name GNUPG.
    • Enter output of previous command in Value.
  2. Add following task to your .gitpod.yml:
tasks:
    - before: >
          [[ ! -z $GNUPG  ]] &&
          cd ~ &&
          rm -rf .gnupg &&
          echo $GNUPG | base64 -d | tar --no-same-owner -xzf -
Enter fullscreen mode Exit fullscreen mode

SSH Github and Gitlab from gitpod

  1. Add SSH Keys to Github and/or Gitlab
  2. Get your SSH Public Key from id_rsa.pub:
    • Create a variable on gitpod.
    • Enter Name SSH_PUBLIC_KEY.
    • Paste the contents of file in Value.
  3. Get your SSH Public Key from id_rsa:
    • Create a variable on gitpod.
    • Enter Name SSH_PRIVATE_KEY.
    • Encode the File id_rsa with base64.
cat id_rsa | base64 -w 0
Enter fullscreen mode Exit fullscreen mode
  • Paste the output of previous command in Value.
  1. Add Following tasks to your .gitpod.yml:
tasks:
    - before: >
          mkdir -p ~/.ssh &&
          [[ ! -z $SSH_PUBLIC_KEY  ]] &&
          echo $SSH_PUBLIC_KEY > ~/.ssh/id_rsa.pub &&
          chmod 644 ~/.ssh/id_rsa.pub &&
          [[ ! -z $SSH_PRIVATE_KEY  ]] &&
          echo $SSH_PRIVATE_KEY | base64 -d > ~/.ssh/id_rsa &&
          chmod 600 ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode

Thank You!

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
dtan13
Dhananjay Tanpure

Posted on December 27, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

ยฉ TheLazy.dev

About