I'm trying to write a script that automatically unlocks all of my rsa keys with ssh-add
on Arch Linux.
I use pass
to store my passwords (encrypted with gpg keys) and I'm trying to pass its input to ssh-add
as follows:
rsa_dir=~/.ssh
cd $rsa_dir
ls -1 id_rsa* |
grep -v '.pub' |
while read file; do
# example: file == id_rsa_github -> keyname == rsa/github
key_name=${file/id_rsa_/rsa/}
# pass will prompt (only once) for the master password, then print out the request password to stdout
pass $key_name | ssh-add $file
done
However, it gives an error:
ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory
But if I just run ssh-add $file
, it prompts for a password and works fine. I don't want to use the default ssh-askpass to get the password. I need to use my own script.
Can someone please help me?
for file in id_rsa*
instead ofls | while
.for
approach is that it will take bothid_rsa
andid_rsa.pub
files. This approach requires adding aif
statement to skip the loop for theid_rsa.pub
find $rsa_dir ! -iregex '.*\.pub$'-print0 | xargs -0 ...
or| while read file