Simplify Multi-Hop SSH Connection Using Config

Tags: April 29, 2016 8:15 PM
0 comments

Goal

Using SSH config to simplify connecting to another host from a host a.k.a multi-hop connection. Diagram for the connection:
+---------------+
| Local Machine |
| 192.168.0.5   |
+---------------+
      |
      | SSH 
       \
       \/
+-------------------------------------+
| Host Machine 192.168.0.10           |
|           /          \              |
|          / -- SSH --  \             |
|  +--------------+  +-------------+  |
|  | Docker 1     |  | Docker 2    |  |
|  | 172.17.0.1   |  | 172.17.0.2  |  |
|  +--------------+  +-------------+  |
|                                     |
+-------------------------------------+

Share on Facebook Twitter

Configure Postfix to Relay to Amazon SES SMTP Server

Tags: April 27, 2016 6:55 AM
0 comments

Goal

Configure internal Postfix installation to relay email to Amazon SES SMTP server.

Steps

Make sure you have done everything that Amazon SES requires you before you're able to send email using Amazon SES. After that you can start to proceed steps below.

1. Install Postfix

$ sudo apt-get install postfix libsasl2-modules

2. Configure SMTP Credential

Make sure you already have Amazon SES username and secret key. Now we need to add the credential into postfix lookup table.
$ sudo cat > /etc/postfix/sasl_passwd
[email-smtp.us-east-1.amazonaws.com]:587 YOUR_USERNAME:YOUR_SECRET_KEY
$ sudo chmod 0600 /etc/postfix/sasl_passwd
You may change the smtp server email-smtp.us-east-1.amazonaws.com according region where you setup the Amazon SES. Now update the postfix lookup table.
$ sudo postmap /etc/postfix/sasl_passwd

Share on Facebook Twitter

How to Fix Multi-Hop SSH Forward Agent Issue

Tags: April 25, 2016 11:41 AM
0 comments

Problem

You want to connect to the 3rd SSH machine but using the key from the 1st hop not from your local machine. Here is the diagram:
+-----------------------+
|  Local Machine (LM)   |
+-----------------------+
            |
            |
+-------------------------+
|  Remote Machine 1 (RM1) | -> 1st Hop
+--------------------------+
            |
            |
+-------------------------+
|  Remote Machine 2 (RM2) | -> 2nd Hop  
+-------------------------+
            |
            |
+-------------------------+
|  Remote Machine 3 (RM3) | -> 3rd Hop
+-------------------------+
Commands listed below shown what issue we had with the forward agent.
[email protected]~$ ssh -A remote-machine-1

[email protected]~$ ssh -A remote-machine-2
(Permission denied)
The authentication was fail because RM2 expect key from RM1 but which ssh agent sent was key from Local Machine.

Share on Facebook Twitter

Reset All Tables Except Migration Table on MySQL

Tags: April 15, 2016 9:29 PM
0 comments

Overview

When developing an application there is case when you need to clear all the data in your database e.g: testing the seeding or such. But you want to exclude some tables let say migration table which used by the application framework to migrate the schema.

Problem

You want to clean up data on all the tables, except the migration table because you don't want to re-run the schema migration.

Solution

  1. Get list of tables
  2. Exclude the migration table
  3. Append the prefix 'DELETE FROM ' to each line
  4. Append the suffix ';' to each line
  5. Pipe the result to MySQL
$ echo "SHOW TABLES;" | mysql -N DB_NAME | grep -v orb_migration | sed -e 's/^/DELETE FROM /' -e 's/$/;/' | mysql DB_NAME
In case above the table which excluded is orb_migration.

Share on Facebook Twitter