Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I use ssh regularly and have ssh-agent set up.

How can I use ssh keys to gpg-encrypt a file?

Edit: It seems that this is impossible. Why? ssh can encrypt traffic, so why not also files?

share|improve this question
    
See also gpg-agent. –  dmourati Jan 8 at 21:00
add comment

2 Answers

up vote 5 down vote accepted

No, SSH keys are not PGP keys and serve different purpose .
You must have PGP keys in GnuPG keyring.
But - you can convert GPG keys to SSH keys (using gpgkey2ssh) and gpg-agent can take care of SSH keys (using --enable-ssh option). I believe no such tool exists for converting SSH keys to GPG keys and cannot exist.

share|improve this answer
    
I prefer to work in the reverse: use gpg with ssh keys, since I already have an extensive ssh infrastructure. –  nalply Sep 15 '10 at 12:15
    
that is not possible. Just view size of SSH public key and GPG public key -> SSH key contains much less info. –  Kristaps Sep 15 '10 at 18:34
1  
Okay, some things are not possible with SSH keys but I believe that encryption is possible since ssh encrypts traffic. Perhaps I should have asked: How can I encrypt a file with an SSH key? –  nalply Sep 16 '10 at 11:48
1  
unix.stackexchange.com/questions/27005/… answers that question. –  ceejayoz Jan 8 at 19:56
add comment

It seems that this is impossible. Why? ssh can encrypt traffic, so why not also files?

SSH can encrypt, just not in a GPG compatible manner.

Per http://unix.stackexchange.com/questions/27005/encrypting-file-only-with-ssh-priv-key:

openssl enc -aes-256-cbc -in my.pdf -out mydata.enc 

and

openssl enc -aes-256-cbc -d -in mydata.enc -out mydecrypted.pdf

should do the trick.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.