Exporting PGP Keys over SSH using a script run by Node.JS

I’m trying to export PGP sub keys to a remote machine using this script:

#!/bin/bash
ssh-keyscan -H $REMOTE_MACHINE >> /root/.ssh/known_hosts
gpg2 --verbose --export-secret-key 
    $EXPORT_THIS_ID | sshpass -p $REMOTE_PASS 
    ssh <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3d196f787072697862686e786f7d">[email protected]</a>$REMOTE_MACHINE 
    gpg2 --verbose --import
echo '' > /root/.ssh/known_hosts

and am getting a response of:

# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
gpg: writing to stdout
gpg: WARNING: nothing exported
Permission denied, please try again.

This is done from a nodejs backend, the script is run using child.spawn and the response is piped to the frontend to be displayed to the user.

I see gpg says writing to stdout, but am not sure where to go from here.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The above script works perfectly. My issue was how I was passing the $REMOTE_PASS variable to the script. For those who come across this, beware of special chars in the password. Encapsulate the pass in ""(inverted commas) if necessary. For security purposes don’t handle passwords like this if the password is highly secret.

In my case, the password is no longer usable after this initial connection.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x