Extremely Serious

Author: ron (Page 24 of 36)

Basic Postfix Management

CommandDescription
postqueue -pDisplay the queue
postcat -vq <QUEUE_ID>View the content of the email
postsuper -d ALLRemove all emails
postsuper -d <QUEUE_ID>Remove a particular email
postqueue -i <QUEUE_ID>Attempt to send one particular email
Token Description
QUEUE_ID Can be identified by displaying the queue.

Using Rsync to Sync a Local Directory to Another Local Directory

Syntax

To sync some of your local directories to another local directory, you can use the following syntax:

rsync -av -L --delete <DIR1>[[ <DIR2>] <DIRn>] <DESTINATION_DIR>
Token Description
DIR1, DIR2, DIRn These are the local directories you've wanted to be synced. Only DIR1 is required and the rest are optional.
DESTINATION_DIR The destination directory on the remote machine.

Example

rsync -av -L --delete /var/log/ /data/log/

Useful Environment Variable for Git Troubleshooting

VariableDescriptionPossible Values
GIT_CURL_VERBOSETells Git to emit all the messages generated by that library. This is similar to doing curl -v on the command line.1
GIT_SSL_NO_VERIFYTells Git not to verify SSL certificates.true
GIT_TRACEControls general traces1, 2 or true
GIT_TRACE_PACKETEnables packet-level tracing for network operations.true

Generating SSH Key Pair

  1. Execute the following command:
    ssh-keygen -t ed25519
  2. Distribute the public key using the following syntax:
    ssh-copy-id -i ~/.ssh/id_ed25519.pub <USER>@<HOST>
    Token Description
    USER A valid user on the host computer.
    HOST The host that has an active ssh service.

    If ssh-copy-id command doesn't work, you can directly append the content of the id_ed25519.pub file to the ~/.ssh/authorized_keys file (i.e. create this file if it doesn't exists) of the target <USER> on the target <HOST>.

Creating an Email Alias

Create a new alias for postfix service by updating the following file:

/etc/aliases

Each entry in the file must have the following syntax:

<ALIAS>: <USER1>[[, <USER2>], <USERn>]
Token Description
ALIAS The desired email alias.
USER1, USER2, USERn USER1 is required and the rest are optional. Each user must be delimited by a comma.

The target user of the alias must be a valid user of the system with a home directory.

Example:

postmaster: root

After updating the file, you must execute the following command:

sudo newaliases

Using Embedded Derby in Java 9 with Gradle

  1. Add the following dependencies to your build.gradle file:
    compile group: 'org.apache.derby', name: 'derby', version: '10.15.1.3'
    compile group: 'org.apache.derby', name: 'derbyshared', version: '10.15.1.3'
  2. Add the following entries to your module-info.java file:
    requires org.apache.derby.engine;
    requires org.apache.derby.commons;
    requires java.sql;
    
  3. In your Java class, you can create a connection like the following:
    final String DATABASE_NAME = "sample_table";
    String connectionURL = String.format("jdbc:derby:%s;create=true", DATABASE_NAME);
    connection = DriverManager.getConnection(connectionURL);
    
  4. Do your needed database operations with the connection (e.g. create table, execute a query, or call a stored procedure.).
  5. When your done using the connection, close the connection and shutdown the Derby engine like the following:
    connection.close();
    
    boolean gotSQLExc = false;
    try {
        //shutdown all databases and the Derby engine
        DriverManager.getConnection("jdbc:derby:;shutdown=true");
    } catch (SQLException se)  {
        if ( se.getSQLState().equals("XJ015") ) {
            gotSQLExc = true;
        }
    }
    if (!gotSQLExc) {
        System.out.println("Database did not shut down normally");
    }

    A clean shutdown always throws SQL exception XJ015, which can be ignored.

Using Values as the Record Source for Select Statement

Values can become a valid record source for select statement if the values has table alias and column names as follows:

SELECT dummy_table.* 
FROM (VALUES ('record1'),
	 ('record2'),
	 ('record3'),
	 ('record4'),
	 ('record5'),
	 ('record6'),
	 ('record7'),
	 ('record8'),
	 ('record9')) dummy_table (column1)

From the preceding select statement, the dummy_table is the table alias and the column name is column1.

Using Detach ASCII Signature to Verify a File

Import Keys from Keyserver

Run the following command:

gpg --receive-keys <KEY_ID>

Showing the Fingerprints

Run the following command:

gpg --fingerprint <KEY_ID>

Verifying a File with ASCII Key

  1. Download the detach asc <ASC_FILE> file associated to the file.
  2. Download the signed file <SIGNED_FILE> file.
  3. Use the following command for verification:
    gpg --verify <ASC_FILE> <SIGNED_FILE>

Generating PGP Keys with Gpg4win

Pre-requisite

Generating Keys

    1. Run the following command:
      gpg --full-gen-key
    2. Type 1 and press enter for the following question:
      Please select what kind of key you want:
         (1) RSA and RSA (default)
         (2) DSA and Elgamal
         (3) DSA (sign only)
         (4) RSA (sign only)
      Your selection?
    3. Press enter for the following question:
      RSA keys may be between 1024 and 4096 bits long.
      What keysize do you want? (2048)
    4. Press enter for the following question:
      Please specify how long the key should be valid.
               0 = key does not expire
            <n>  = key expires in n days
            <n>w = key expires in n weeks
            <n>m = key expires in n months
            <n>y = key expires in n years
      Key is valid for? (0)
    5. Type y and press enter for the following question:
      Key does not expire at all
      Is this correct? (y/N)
    6. Fill in the Real name appropriately and press enter.
    7. Fill in the Email address appropriately and press enter.
    8. The Comment is optional but don't forget to press enter.
    9. Type o and press enter for the following question:
      Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit?
    10. Fill-in the passphrase appropriately.

The output will be ending with something like the following:

pub   rsa2048 2019-11-27 [SC]
      8C99E30527B112D1CB6D646FE86A4FE7189AADC9
uid                      Real Name <real_email@email.com>
sub   rsa2048 2019-11-27 [E]

The second line is the PGP key ID. Thus from the output above. The key id is:

8C99E30527B112D1CB6D646FE86A4FE7189AADC9

Exporting Your Private Key

The my-secret-key.pgp file generated by this command can be use for signing your binaries.

Run the following command:

gpg --export-secret-keys <KEY_ID> > my-secret-key.pgp

DO NOT SHARE THIS FILE OR COMMIT TO YOUR REPOSITORY.

Publishing Your Public Key

Run the following command:

gpg --keyserver hkp://keys.openpgp.org --send-keys <KEY_ID>

Validating your Published Public Key

  1. You can validate the upload public key by placing your <KEY_ID> as a Search String from the following address: https://keys.openpgp.org.

    This will only work if you submit your keys using the preceding section.

  2. Click the Search button.
« Older posts Newer posts »