-
-
Save Norbert515/2f14c07371472d655b8a67bd4dfee7c6 to your computer and use it in GitHub Desktop.
Wrapper around `ssh` to pick the right one from several GitHub deploy keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# The last argument is the command to be executed on the remote end, which is something | |
# like "git-upload-pack 'webfactory/ssh-agent.git'". We need the repo path only, so we | |
# loop over this last argument to get the last part of if. | |
for last in ${!#}; do :; done | |
"I STARTED RUNNING" >> /home/runner/work/log.txt | |
$last >> /home/runner/work/log.txt | |
# Don't use "exec" to run "ssh" below; then the trap won't work. | |
key_file=$(mktemp -u) | |
trap "rm -f $key_file" EXIT | |
eval last=$last | |
# Try to pick the right key | |
ssh-add -L | grep --word-regexp --max-count=1 $last > $key_file | |
ssh -i $key_file "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment