July 2019
M T W T F S S
« Jun    
1234567
891011121314
15161718192021
22232425262728
293031  

Categories

WordPress Quotes

I've learned that you shouldn't go through life with a catcher's mitt on both hands; you need to be able to throw something back.
Maya Angelou
July 2019
M T W T F S S
« Jun    
1234567
891011121314
15161718192021
22232425262728
293031  

Short Cuts

2012 SERVER (64)
2016 windows (9)
AIX (13)
Amazon (36)
Ansibile (19)
Apache (134)
Asterisk (2)
cassandra (2)
Centos (211)
Centos RHEL 7 (267)
chef (3)
cloud (2)
cluster (3)
Coherence (1)
DB2 (5)
DISK (25)
DNS (9)
Docker (30)
Eassy (11)
ELKS (1)
EXCHANGE (3)
Fedora (6)
ftp (5)
GIT (3)
GOD (2)
Grub (1)
Hacking (10)
Hadoop (6)
health (1)
horoscope (23)
Hyper-V (10)
IIS (15)
IPTABLES (15)
JAVA (7)
JBOSS (32)
jenkins (1)
Kubernetes (7)
Ldap (5)
Linux (188)
Linux Commands (166)
Load balancer (5)
mariadb (14)
Mongodb (4)
MQ Server (24)
MYSQL (84)
Nagios (5)
NaturalOil (13)
Nginx (35)
Ngix (1)
openldap (1)
Openstack (6)
Oracle (35)
Perl (3)
Postfix (19)
Postgresql (1)
PowerShell (2)
Python (3)
qmail (36)
Redis (12)
RHCE (28)
SCALEIO (1)
Security on Centos (29)
SFTP (1)
Shell (64)
Solaris (58)
Sql Server 2012 (4)
squid (3)
SSH (10)
SSL (14)
Storage (1)
swap (3)
TIPS on Linux (28)
tomcat (62)
Uncategorized (29)
Veritas (2)
vfabric (1)
VMware (28)
Weblogic (38)
Websphere (71)
Windows (19)
Windows Software (2)
wordpress (1)
ZIMBRA (17)

WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

Who's Online

23 visitors online now
1 guests, 22 bots, 0 members

Hit Counter provided by dental implants orange county

GPG file encryption command line in Linux

GPG file encryption using key pair
GPG basic file encryption doesn’t required public/private key. But to make a encrypted file more secure you can use RSA/DSA algorithms. These algorithms generates public and private keys to encrypt file.

There are three criteria to use GPG file encryption.

1. Encrypt/Decrypt file locally for same user account.
2. Encrypt file for other user.
3. Decrypt other users file.

The very first step is to generate key pair using below command.

# gpg –gen-key
Output:

gpg (GnuPG) 1.4.5; Copyright (C) 2006 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.

Please select what kind of key you want:
(1) DSA and Elgamal (default)
(2) DSA (sign only)
(5) RSA (sign only)
Your selection?
DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
0 = key does not expire
= key expires in n days
w = key expires in n weeks
m = key expires in n months
y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
“Heinrich Heine (Der Dichter) ”

Real name: Mohan Ramadoss
Email address: rmohan@rmohan.com
Comment: System Admin
You selected this USER-ID:
“Mohan Ramadoss (System Admin) ”

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
You need a Passphrase to protect your secret key.

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
++++++++++++++++++++..+++++++++++++++.++++++++++++++++++++.+++++.+++++.+++++++++++++++++++++++++.+++++.++++++++++++++++++++++++++++++…+++++>+++++..+++++>+++++……………………………………………………..+++++

Not enough random bytes available. Please do some other work to give
the OS a chance to collect more entropy! (Need 284 more bytes)

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
+++++..+++++.++++++++++..++++++++++.++++++++++..++++++++++..+++++++++++++++.+++++..+++++.++++++++++.+++++.++++++++++.++++++++++..++++++++++++++++++++++++++++++..+++++>++++++++++.>+++++>+++++.<+++++………………………………………………………………………………………….>+++++…………………+++++^^^
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 2AE39E50 marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
pub 1024D/2AE39E50 2013-03-14
Key fingerprint = 0D89 4697 E22A A6CC 3017 5EA1 0389 ED6D 2AE3 9E50
uid Mohan Ramadoss (System Admin)
sub 2048g/9102AC9C 2013-03-14
1. Encrypt/Decrypt file locally for same user account.

Encrypt file for single user only. No one other can decrypt this file.

# gpg –encrypt –recipient ‘Mohan Ramadoss’ rmohan.txt
–recipient name should be same as used in key generation. Above command will automatically generate a encrypted file named rmohan.txt.gpg

Decrypt your own file rmohan.txt.gpg

# gpg –output rmohan2.txt –decrypt rmohan.txt.gpg
–output or -o is used to specify output filename. Above command will prompt for passphrase used in key pair.

2. Encrypt file for other user.

Use #1 steps to generate encrypted file. Finally share your public key and encrypted file ( rmohan.txt.gpg ) with other users. To export your public key use following command.

# gpg –armor –output pubkey.txt –export ‘Mohan Ramadoss’

Check your public key. It should be like below

# cat pubkey.txt
—–BEGIN PGP PUBLIC KEY BLOCK—–
Version: GnuPG v1.4.5 (GNU/Linux)

mQGiBFFBPwsRBADWAxKxCxLsZ1ZJ512auBkEw51HlF5+k18Yp1giOqIYtbRUPVeq
Y5o5knVKjlJDlVA0/rGh18fbKgubjZl1PL1R+tT0bMIDIs5+hg+S60nSlxBGOhYz
8h+nuY4GbOMdG0V4DJwgpOg7Haywljs0epYPtcdroRIrLg8owjcpYtIm1wCgl75F
XP6XU/CPJJoZp7DrC2Ukrg8EALra/Rwk5MXi3G8rT3dq1rX0wMmFPh+A1osnYIlM
RaaNGi28MdTGv/61pMz6ItPgBTglp6hzkRyixIuBXxqkwP8489o2MwzzwVbAUjUb
i8/U4Y3eW1jii8WBZydUn+MaMx4sKSnYXjoIHvRsiDhnIWvVUdbaeet0wO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emJFywumlTrnihycRXEElxur+23NSLQpeNaw
M6gUQPeISQQYEQIACQUCUUE/EAIbDAAKCRADie1tKuOeUB+VAJ9e8PprKcX3qvnW
rU8MhhXMB/G0PQCfehvC8uWR/TLtHyu5pjzCEtcsX/E=
=k3yQ
—–END PGP PUBLIC KEY BLOCK—–
3. Decrypt other users file.

To decrypt other users file, It required public key of that user. Import that public key to your account using below command. For example other users public file is otherpub.txt

# gpg –import otherpub.txt
Make sure that file has been imported successfully using below command.

# gpg –list-keys
Above command will show all public key in your account. Make sure the other users public key also exist there.

Now you can decrypt the other users file using below command

# gpg –output otheruserfile.txt otheruserfile.txt.gpg
GPG file encryption command line in Linux

AS we know, now a days it’s not safe to send and receive data over internet. There are many option available to secure your data while traveling over internet. GnuPG also provides you to encrypt your data on key basis. GPG is an encryption and signing tool for UNIX/LINUX like OS.

GnuPG provides many methods for file encryption and decryption.

Method (A): Use Basic GPG encryption

Step 1: First create a file to encrypt using GPG.

# echo “Enter file content here” > secureit.txt
Step 2: Encypt above created file using gpg.

# gpg -c secureit.txt
Above command will create a encrypted file named secureit.txt.gpg. Original file will remain same.

# ls -l
total 8
-rw-r–r– 1 root root 24 Mar 9 21:36 secureit.txt
-rw-r–r– 1 root root 74 Mar 9 21:36 secureit.txt.gpg
Step 3: Finally how to decrypt file again.

# gpg -o secureit-new.txt -d secureit.txt.gpg
gpg: CAST5 encrypted data
Enter passphrase:
You will get a new decypted file named secureit-new.txt.

# ls -l secureit-new.txt
-rw-r–r– 1 root root 24 Mar 9 21:56 secureit-new.txt
Thanks for using this article.

 

 

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Blue Captcha Image
Refresh

*

Protected by WP Anti Spam