#!/bin/sh # We can figure out the password for the key based on $1 # which is in the following form: # Enter passphrase for key 'path/to/key': # The point is to retrieve the path and use the final name of the key # find the according password. key="$(printf '%s\n' "$1" | cut -f 2 -d \' | awk -F '/' '{print $NF}')" pass="keys/$(hostname)/ssh/$key" pass show "$pass" | head -n 1