DKIM on postfix and bind

Open dkim on postfix


yum install opendkim

## cp /etc/opendkim.conf{,.orig}
## vim /etc/opendkim.conf

AutoRestart             Yes
AutoRestartRate         10/1h
LogWhy                  Yes
Syslog                  Yes
SyslogSuccess           Yes
Mode                    sv
Canonicalization        relaxed/simple
ExternalIgnoreList      refile:/etc/opendkim/TrustedHosts
InternalHosts           refile:/etc/opendkim/TrustedHosts
KeyTable                refile:/etc/opendkim/KeyTable
SigningTable            refile:/etc/opendkim/SigningTable
SignatureAlgorithm      rsa-sha256
Socket                  inet:8891@localhost
PidFile                 /var/run/opendkim/opendkim.pid
UMask                   022
UserID                  opendkim:opendkim
TemporaryDirectory      /var/tmp

Generate set of keys for your mydomain.com domain name:

## mkdir /etc/opendkim/keys/mydomain.com
## opendkim-genkey -D /etc/opendkim/keys/mydomain.com/ -d mydomain.com -s default
## chown -R opendkim: /etc/opendkim/keys/mydomain.com
## mv /etc/opendkim/keys/mydomain.com/default.private /etc/opendkim/keys/mydomain.com/default


add mydomain.com to OpenDKIM’s key table by adding the following record in /etc/opendkim/KeyTable

default._domainkey.mydomain.com mydomain.com:default:/etc/opendkim/keys/mydomain.com/default
next, edit /etc/opendkim/SigningTable and add the following record to OpenDKIM’s signing table:

*@mydomain.com default._domainkey.mydomain.com


And add your domain and your hostname as trusted hosts in /etc/opendkim/TrustedHosts  

127.0.0.1
mydomain.com
host.mydomain.com
assuming the domain in question is ‘mydomain.com’ and server’s hostname is set to ‘host.mydomain.com’

finally, edit your mydomain.com DNS zone and add the TXT record from

/etc/opendkim/keys/mydomain.com/default.txt

default._domainkey      IN      TXT     ( "v=DKIM1; k=rsa; "
          "p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDApHRr7ZmXRaAB+RQRbP4VdMwIrIHIP18KFtXRsv/xpWc0Gix6ZXN13fcG03KNGKZo2PY+csPkGC5quDnH5V0JEhDZ78KcDWFsU6u4fr9ktVAdt6P7jWXjcyqdHOZ8+YN4cAeU4lRFNgQvdupIcByYwzPYMgBFHfJm9014HvRqhwIDAQAB" )  ; ----- DKIM key default for mydomain.com


Verify by 
## dig +short default._domainkey.mydomain.com TXT

CONFIGURE POSTFIX

In order to integrate OpenDKIM with Postfix we need to add the following few lines in /etc/postfix/main.cf:

smtpd_milters           = inet:127.0.0.1:8891
non_smtpd_milters       = $smtpd_milters
milter_default_action   = accept
milter_protocol         = 2

## service opendkim start
## chkconfig opendkim on
## service postfix restart





 ## cp /etc/opendkim.conf{,.orig}
## vim /etc/opendkim.conf

AutoRestart             Yes  #Automatically re-start on failures.  Use with caution; if the filter fails instantly after it starts, this can cause a tight fork(2) loop

AutoRestartRate         10/1h  # This is a string of the form n/t[u] where n is an integer limiting the count of restarts in the given interval and t[u] defines the time  inter‐
              val  through which the rate is calculated;

LogWhy                  Yes # If  logging is enabled (see Syslog below), issues very detailed logging about the logic behind the filter's decision to either sign a message or verify it
Syslog                  Yes

SyslogSuccess           Yes #Log via calls to syslog(3) additional entries indicating successful signing or verification of messages.

Mode                    sv   # Valid modes  are  s
              (signer)  and  v (verifier).  The default is sv except in test mode (see the opendkim(8) man page) in which case the default is v.  When signing
              mode is enabled, one of the following combinations must also be set: (a) Domain, KeyFile, Selector, no KeyTable, no SigningTable; (b)  KeyTable,
              SigningTable, no Domain, no KeyFile, no Selector; (c) KeyTable, SetupPolicyScript, no Domain, no KeyFile, no Selector.


Canonicalization        relaxed/simple   #  Selects the canonicalization method(s) to be used when signing messages.  When verifying, the message's DKIM-Signature: header  field  specifies
              the  canonicalization  method.   The recognized values are relaxed and simple as defined by the DKIM specification.  The default is simple.  The
              value may include two different canonicalizations separated by a slash ("/") character, in which case the first will be applied  to  the  header
              and the second to the body.


ExternalIgnoreList      refile:/etc/opendkim/TrustedHosts
InternalHosts           refile:/etc/opendkim/TrustedHosts
KeyTable                refile:/etc/opendkim/KeyTable
SigningTable            refile:/etc/opendkim/SigningTable
SignatureAlgorithm      rsa-sha256
Socket                  inet:8891@localhost
PidFile                 /var/run/opendkim/opendkim.pid
UMask                   022
UserID                  opendkim:opendkim
TemporaryDirectory      /var/tmp

policyd

yum install perl-Net-Server perl-Config-IniFiles perl-Cache-FastMmap perl-Mail-SPF php php-pdo php-mysqli
wget https://download.policyd.org/v2.0.14/cluebringer-v2.0.14.tar.bz2

tar xvfj cluebringer-v2.0.14.tar.bz2
cd cluebringer-v2.0.14/database/

for i in core.tsql access_control.tsql quotas.tsql amavis.tsql checkhelo.tsql checkspf.tsql greylisting.tsql
  do
  ./convert-tsql mysql $i
 done > policyd.sql




 create database policyd in mysql

  mysql policyd < policyd.sql


yum install perl-Net-Server perl-Config-IniFiles perl-Cache-FastMmap perl-Mail-SPF php php-pdo php-mysqli
wget https://download.policyd.org/v2.0.14/cluebringer-v2.0.14.tar.bz2

tar xvfj cluebringer-v2.0.14.tar.bz2
cd cluebringer-v2.0.14/database/

for i in core.tsql access_control.tsql quotas.tsql amavis.tsql checkhelo.tsql checkspf.tsql greylisting.tsql
  do
  ./convert-tsql mysql $i
 done > policyd.sql

 create database policyd in mysql

  mysql policyd < policyd.sql

mkdir /usr/local/lib/cbpolicyd
cp -r cbp /usr/local/lib/cbpolicyd
cp cbpadmin /usr/local/bin/
cp cbpolicyd /usr/local/sbin/
cp cluebringer.conf /etc/

mkdir /var/log/cbpolicyd
mkdir /var/run/cbpolicyd

yum install perl-Config-IniFiles-2.72-2.el6
wget ftp://195.220.108.108/linux/centos/6.9/os/x86_64/Packages/perl-List-MoreUtils-0.22-10.el6.x86_64.rpm
yum install perl-List-MoreUtils-0.22-10.el6.x86_64.rpm


mkdir /usr/local/lib/cbpolicyd
cp -r cbp /usr/local/lib/cbpolicyd
cp cbpadmin /usr/local/bin/
cp cbpolicyd /usr/local/sbin/
cp cluebringer.conf /etc/

mkdir /var/log/cbpolicyd
mkdir /var/run/cbpolicyd


postfix fall back relay

postfix per smtp-transport smtp_fallback_relay master.cf

I’d got multiple SMTP transports on my postfix server, but one of these send’s newsletters,
As we already seen this in real life of an mailadmin some servers got rate-limit’s setup, so only a specific
amount of mail is accepted in a specific timeframe.
To get these masses sent to these destinations in a adequate timeframe we need a fallback relay.
Due to the configuration of the destination server these will accept mails from other client IP’s than
the rate-limited server is and they would send an 450 temporary error.
Long speech short sin.
Here as always my config snippet from postfix master.cf (somewhere at line 40):
smtp      unix  -       -       -       -       50       smtp
        -o smtp_fallback_relay=relay01.bla.com
No magic. Really? 

DONT FORGET THE S**** TABSTOP IN FRONT of "-o smtp_fallback_relay="
Otherwhise you gonna get this:

how email works refresher

The SMTP protocol works like this:
1) A client connects to an SMTP server.
2) The SMTP server says “hello”
3) The client authenticates (if necessary) by logging in.
4) Now it’s time to send an email. First, the client sends a “MAIL FROM” command with the email address that is the reverse-path. This is the email address that would receive a bounce or delivery status notification.
Note: The "MAIL FROM" address becomes the "Return-Path" header.
The receiving server adds the "Return-Path" to the email. (Just like it adds the "Received" header.) Therefore, a mail-sending app should never explicitly add the "Return-Path" header. The correct way of specifying the "Return-Path" is to pass the correct email address to "MAIL FROM" (see below).
5) The client then sends one or more “RCPT TO” commands, each with a recipient email address. It doesn’t matter if the recipient is a “To” , “CC”, or “BCC”, all recipient email addresses are passed to the SMTP server via “RCPT TO” commands.
6) Finally, the MIME source of the email is sent with a “DATA” command.
Note: The MIME source has header fields for “From”, “To”, and “CC”. These are the email addresses that will be seen by the receiver of the email. The actual recipients are the email addresses passed via the RCPT TO commands. It’s possible to create an email such that the “To” header field contains “santa.claus@northpole.com”, but you pass actual email addresses in the RCPT TO commands. The person receiving such an email (if not filtered as SPAM) would scratch his/her head and wonder why he/she received an email addressed to Santa Claus.
There are two ways to specify the "Return-Path" (i.e. the email address passed in the "MAIL FROM" command within the SMTP protocol.
1) If sending email by passing an email object to a method such as mailman.SendEmail, then set the emailObject.BounceAddress property. This is the address passed in the "MAIL FROM" command. If BounceAddress is unset, then the email object's From address is used.
2) If sending email by passing the exact MIME string, such as via mailman.SendMime, then the "fromAddr" argument is used.
A Note about BackScatter:
Now that you understand Return-Path, you can understand a problem called BackScatter. When a spammer sends millions of emails, the scoundrel will often pass a real email address (harvested from a web page) to the MAIL FROM command. A certain percentage of those emails are (of course) sent to invalid email addresses. A mail server managed by someone without a good understanding SMTP might configure the server to send DSN's (Delivery Status Notifications) for all undelivered emails. The end result is that the unlucky email address used by the spammer gets mail-bombed with DSN's. A good mail server administrator should either turn off DSN's, or only send DSN's for email known to NOT be SPAM.

part 1 docker getting started

add your user to docker group
# usermod -a -G docker user1

to use docker commands as user1 without logging out of system, run below command as user1

~$ newgrp docker

docker provides many ways to run commands in containers
container are about running process
focusing on "docker run"

docker run ubuntu:latest  ls -lh /etc/postfix

# get inside docker

docker run -i -t ubuntu:latest
type exit to exit



## remove docker container after running the command called "sleep 100"
docker run --rm busybox:1.24  sleep 100


## remove docker container after running the command called "sleep 100"
docker run --rm busybox:1.24  sleep 100

## specify name for docker container we want to run
docker run  --name  mycontainer100 busybox:1.24
docker run  --name  mycontainer200 busybox:latest
docker ps -a

docker inspect containerid
##outpus image id , logpath,mac id

user1@localhost$ docker run -d busybox:latest sleep 10
a7393fc5cc8e1db7e87b9eb24151147

user1@localhost$ docker inspect a7393fc5cc8e1db7e87b9eb24151147


apache 2.4 virtual host template

Alias /PMA /var/www/vhosts/PMA
<VirtualHost *:80>
        ServerName stage.sappersuite.com
        Redirect / https://stage.sappersuite.com
        ServerAdmin webmaster@localhost
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
 ServerName stage.sappersuite.com
 DocumentRoot  /var/www/vhosts/stage.sappersuite.com/html/
 SSLEngine on
 SSLCertificateFile  /etc/ssl/certs/stage.sappersuite.com.crt
 SSLCertificateKeyFile /etc/ssl/private/stage.sappersuite.com.key
ErrorLog ${APACHE_LOG_DIR}/stage.sappersuite.com.error.log
CustomLog ${APACHE_LOG_DIR}/stage.sappersuite.com.access.log combined
<Directory /var/www/vhosts/stage.sappersuite.com/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
</VirtualHost>

phpmyadmin and amazon RDS

on the phpmyadmin folder
vim config.inc.php

#at end of file paste below
$i++;
$cfg['Servers'][$i]['host']          = 'myskdwklji.us-west-2.rds.amazonaws.com';
$cfg['Servers'][$i]['port']          = '3306';
$cfg['Servers'][$i]['socket']        = '';
$cfg['Servers'][$i]['connect_type']  = 'tcp';
$cfg['Servers'][$i]['extension']     = 'mysql';
$cfg['Servers'][$i]['compress']      = TRUE;
$cfg['Servers'][$i]['auth_type']     = 'cookie';
$cfg['Servers'][$i]['user']          = '';
$cfg['Servers'][$i]['password']      = '';

gpg cheat sheet

Filenames are italicized (loosely, some aren't, sorry), so if you see something italicized, think "put my filename there."
I've used User Name as being the name associated with the key. Sorry that isn't very imaginative. I *think* gpg is pretty wide in it's user assignments, ie. the name for my private key is Charles Lockhart, but I can reference that by just putting in Lockhart. That doesn't make any sense, sorry.
to create a key:
gpg --gen-key
generally you can select the defaults.
to export a public key into file public.key:
gpg --export -a "User Name" > public.key

This will create a file called public.key with the ascii representation of the public key for User Name. This is a variation on:
gpg --export
which by itself is basically going to print out a bunch of crap to your screen. I recommend against doing this.
gpg --export -a "User Name"
prints out the public key for User Name to the command line, which is only semi-useful
to export a private key:
gpg --export-secret-key -a "User Name" > private.key

This will create a file called private.key with the ascii representation of the private key for User Name.
It's pretty much like exporting a public key, but you have to override some default protections. There's a note (*) at the bottom explaining why you may want to do this.
to import a public key:
gpg --import public.key

This adds the public key in the file "public.key" to your public key ring.
to import a private key:
NOTE: I've been informed that the manpage indicates that "this is an obsolete option and is not used anywhere." So this may no longer work.
gpg --allow-secret-key-import --import private.key

This adds the private key in the file "private.key" to your private key ring. There's a note (*) at the bottom explaining why you may want to do this.
to delete a public key (from your public key ring):
gpg --delete-key "User Name"
This removes the public key from your public key ring.
NOTE! If there is a private key on your private key ring associated with this public key, you will get an error! You must delete your private key for this key pair from your private key ring first.
to delete an private key (a key on your private key ring):
gpg --delete-secret-key "User Name"
This deletes the secret key from your secret key ring.
To list the keys in your public key ring:
gpg --list-keys

To list the keys in your secret key ring:
gpg --list-secret-keys

To generate a short list of numbers that you can use via an alternative method to verify a public key, use:
gpg --fingerprint > fingerprint
This creates the file fingerprint with your fingerprint info.
To encrypt data, use:
gpg -e -u "Sender User Name" -r "Receiver User Name" somefile

There are some useful options here, such as -u to specify the secret key to be used, and -r to specify the public key of the recipient.
As an example: gpg -e -u "Charles Lockhart" -r "A Friend" mydata.tar
This should create a file called "mydata.tar.gpg" that contains the encrypted data. I think you specify the senders username so that the recipient can verify that the contents are from that person (using the fingerprint?).
NOTE!: mydata.tar is not removed, you end up with two files, so if you want to have only the encrypted file in existance, you probably have to delete mydata.tar yourself.
An interesting side note, I encrypted the preemptive kernel patch, a file of 55,247 bytes, and ended up with an encrypted file of 15,276 bytes.

To decrypt data, use:
gpg -d mydata.tar.gpg
If you have multiple secret keys, it'll choose the correct one, or output an error if the correct one doesn't exist. You'll be prompted to enter your passphrase. Afterwards there will exist the file "mydata.tar", and the encrypted "original," mydata.tar.gpg.
NOTE: when I originally wrote this cheat sheet, that's how it worked on my system, however it looks now like "gpg -d mydata.tar.gpg" dumps the file contents to standard output. The working alternative (worked on my system, anyway) would be to use "gpg -o outputfile -d encryptedfile.gpg", or using mydata.tar.gpg as an example, I'd run "gpg -o mydata.tar -d mydata.tar.gpg". Alternatively you could run something like "gpg -d mydata.tar.gpg > mydata.tar" and just push the output into a file. Seemed to work either way.
Ok, so what if you're a paranoid bastard and want to encrypt some of your own files, so nobody can break into your computer and get them? Simply encrypt them using yourself as the recipient.
I haven't used the commands:
gpg --edit-key
gpg --gen-revoke

  • --gen-revoke creates a revocation certificate, which when distributed to people and keyservers tells them that your key is no longer valid, see http://www.gnupg.org/gph/en/manual/r721.html
  • --edit-key allows you do do an assortment of key tasks, see http://www.gnupg.org/gph/en/manual/r899.html


Sharing Secret Keys

NOTE!: the following use cases indicate why the secret-key import/export commands exist, or at least a couple ideas of what you could do with them. HOWEVER, there's some logistics required for sharing that secret-key. How do you get it from one computer to another? I guess encrypting it and sending it by email would probably be ok, but I wouldn't send it unencrypted with email, that'd be DANGEROUS.
Use Case *.1 : Mentioned above were the commands for exporting and importing secret keys, and I want to explain one reason of why maybe you'd want to do this. Basically if you want one key-pair for all of your computers (assuming you have multiple computers), then this allows you export that key-pair from the original computer and import it to your other computers.
Use Case *.2 : Mentioned above were the commands for exporting and importing secret keys, and I want to explain one reason of why maybe you'd want to do this. Basically, if you belonged to a group, and wanted to create a single key-pair for that group, one person would create the key-pair, then export the public and private keys, give them to the other members of the group, and they would all import that key-pair. Then a member of the group or someone outside could use the group public key, encrypt the message and/or data, and send it to members of the group, and all of them would be able to access the message and/or data. Basically you could create a simplified system where only one public key was needed to send encrypted stuffs to muliple recipients.

Install docker on ubuntu 14/04

# sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

# apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual

# add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"

# apt-get install docker-ce -y

mysql repo for linux

Mysql repository:-

https://dev.mysql.com/downloads/repo/

https://dev.mysql.com/downloads/repo/yum/     for centos

https://dev.mysql.com/downloads/repo/apt/       for ubuntu