Skip to content

Instantly share code, notes, and snippets.

@aucampia
Last active September 24, 2021 14:56
Show Gist options
  • Save aucampia/c09f26eb7addc093af3f405045d60f10 to your computer and use it in GitHub Desktop.
Save aucampia/c09f26eb7addc093af3f405045d60f10 to your computer and use it in GitHub Desktop.
SSH into AZDO hosted agents
  1. Create a variable group (e.g. iwana-private)
  2. Add your NGROK_AUTHTOKEN in there
  3. Put your ssh key in pipeline (${your_ssh_key_here})
  4. Run the pipeline

To ssh into it, get the ngrok endpoint from https://dashboard.ngrok.com/endpoints/status

then ssh into it:

ssh -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null vsts@${ngrok_domain} -p${ngrok_port}

To end session:

sudo bash -c 'pkill -x sshd; pkill -x ngrok;'
variables:
- group: iwana-private
stages:
- stage: stage_main
displayName: main stage
jobs:
- job: job_main
displayName: main job
pool:
vmImage: "ubuntu-20.04"
steps:
- bash: |
set -x
id
chmod -R go-rwx ~/
set -eo pipefail
sudo apt-get install -y socat openssh-server unzip wget
sudo mkdir -vp /run/sshd
sudo /usr/sbin/sshd -D &
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
chmod +x ngrok
set +x
./ngrok authtoken ${NGROK_AUTHTOKEN}
set -x
mkdir -vp ~/.ssh/
echo "${your_ssh_key_here}" >> ~/.ssh/authorized_keys
chmod -vR go-rwx ~/.ssh/ || :
cat ~/.ssh/authorized_keys
./ngrok tcp 22
env:
NGROK_AUTHTOKEN: $(NGROK_AUTHTOKEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment