# How to use GPG?

### How to create key?

Simply we can run this:

```bash
gpg --full-gen-key
```

Then we will have some interactives.

1. Key Type
    
    It's optional, but I oftenly use RSA and RSA (number 1)
    
2. Keysize (Bits)
    
    It's more secure to have more bit or simply we can take the maximum bit, let's say maximum number is 4096, then we can put 4096
    
3. Expiration Time
    
    If we want to use this key on all the time, we can set to `0` to have the never expired key.
    
4. Expiration confirmation
    
    let say I set `0` as the expiration date which mean it will never get expired, then it will try to confirm us that we really want to create a key which never get expired.
    
5. Identity
    
    1. Name
        
        Put your name, minimum length is 5.
        
    2. Email
        
        You'll never get email for this, it's just for identification purposes. (optional)
        
    3. Comment
        
        Just another information we want to put, maybe to identifying something. (optional)
        
6. Identity confirmation
    
    It will ask you to confirm your identity, we can input `O` (O / Oscar character) to confirm that it's correct.
    
7. Password
    
    Finally we can put password for the created key, we're going to need this password to decrypt encrypted file.
    

### How to Encrypt file?

```bash
gpg -r <uid> -e your-whatever-file.zip
```

replace &lt;uid&gt; with your created key, then a new file with the `.gpg` extension will be created.

### How to Decrypt File?

```bash
gpg -d your-whatever-file.zip.gpg
```

or if we want to put the unlocked data into a file, we can use

```bash
gpg -d your-whatever-file.zip.gpg > your-whatever-file.zip
```

### How to List all existing keys?

```bash
gpg --list-keys
```

or we can just specify a &lt;uid&gt; to know the information of specific key

```bash
gpg --list-keys <uid>
```

### How to Export Key?

```bash
gpg --export-secret-keys <uid> > output.key
```

You're going to type your password to able to export the key.

### How to Import Key?

```bash
gpg --import output.key
```

Or use gpg2 if you don’t want to input passphrase

```bash
gpg2 --batch --import output.key
```

### How to Delete Key?

to be able to delete the keys, we need to delete the secret key first, then deleting the key.

```bash
gpg --delete-secret-keys <uid>
gpg --delete-keys <ui>
```

---

References:

* [https://youtu.be/DMGIlj7u7Eo](https://s.id/1GInV)
    
* [https://linuxhint.com/solve-gpg-decryption-failed-no-secret-key-error/](https://s.id/1GIo1)
    
* [https://stackoverflow.com/a/34132924](https://s.id/1GIqA)
