Tuesday 15 December 2020

gpg encrypt and decrypt at other server

 First generate keys.
1. gpg --gen-key
      Type 1 and Enter for RSA and RSA (default)
      What keysize do you want? (2048) : --- Just Enter
      Key is valid for? (0): --- Just Enter
      Is this correct? (y/N): y --- Type y and Enter
      Real name: Dheeraj --- Type your Name
      Email address: dhirajkumar**5@gmail.com --- Type your email address
      Comment: First GPG --- Type any comment
      Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O --- Type O and Enter
      Enter passphrase: 12345678 --- Type any passphrase and remember this
      Repeat passphrase: 12345678 --- Type same as above
      Do any activities on your computer it will record and create keys.
     
2.  Optional Step:
     Check your keys

     gpg --list-secret-keys
sec   2048R/02551747 2020-12-15
uid                  Dheeraj (First GPG) <dhirajkumar055@gmail.com>
ssb   2048R/7C97C661 2020-12-15

3. Optinal Step:
    mkdir gpg_keys
    cd gpg_keys
    echo "12345" >textfile1
    echo "67890" >textfile2
    tar -cvf textfile.tar textfile1 textfile2
   
Note: We will encrypt textfile.tar and decrypt it.

4. Sign the file you want to encrypt like textfile.tar
    gpg --sign textfile.tar
    A new file with textfile.tar.gpg will be created.
    Send this generated file like textfile.tar.gpg at the destination server.

5. Optional Step: Verify the .gpg file
    gpg --verify textfile.tar.gpg
gpg: Signature made Tuesday 15 December 2020 02:34:20 PM IST using RSA key ID F085C77B
gpg: Good signature from "dheeraj <dhirajkumar055@gmail.com>"

6. Optional Step:
    mkdir publickeys
    cd publickeys

7. Export public key
    gpg --export -a dheeraj >dheerajpublic.key

8. Send the dheerajpublic.key to the destination server and import it at destination.
    gpg --import dheerajpublic.key

9. At destination
    gpg --output textfile.tar -d textfile.tar.gpg

Summary
At source :
    gpg --gen-key
   
gpg --sign textfile.tar
    gpg --export -a dheeraj >dheerajpublic.key
    scp or cp textfile.tar.gpg and dheerajpublic.key
At Destination:
    gpg --import dheerajpublic.key
    gpg --output textfile.tar -d textfile.tar.gpg







 

No comments:

Post a Comment