Skip to content

Instantly share code, notes, and snippets.

@MaxPeal
Forked from mpdude/ssh-deploy-key-wrapper.sh
Created October 5, 2021 07:23
Show Gist options
  • Select an option

  • Save MaxPeal/c4623c4a413049e1a4a798c67d9b36bb to your computer and use it in GitHub Desktop.

Select an option

Save MaxPeal/c4623c4a413049e1a4a798c67d9b36bb to your computer and use it in GitHub Desktop.

Revisions

  1. @mpdude mpdude revised this gist Sep 7, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ssh-deploy-key-wrapper.sh
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,6 @@ trap "rm -f $key_file" EXIT
    eval last=$last

    # Try to pick the right key
    ssh-add -L | grep --word-regexp $last > $key_file
    ssh-add -L | grep --word-regexp --max-count=1 $last > $key_file

    ssh -i $key_file "$@"
  2. @mpdude mpdude created this gist Sep 7, 2020.
    17 changes: 17 additions & 0 deletions ssh-deploy-key-wrapper.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/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

    # 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 $last > $key_file

    ssh -i $key_file "$@"