Postfix configuration

To reconfigure:

sudo dpkg-reconfigure postfix

To check config/manual edit:

emacs /etc/postfix/main.cf

Reloading config:

/etc/init.d/postfix reload

Testing email send (You need mutt installed):

#!/bin/bash
mailsen () {
    SUB="$1"
    BODY=$2
    echo $BODY | mutt -a $BDIR/$COMPLOG -s $SUB -- $RECI
    echo "Send mail test done"
}
touch /tmp/testmail
echo "Testing" >> /tmp/testmail
#RECI="[email protected]"
RECI="[email protected]"
# BDIR=~/"backups"
BDIR="/tmp"
COMPLOG="testmail"
mailsen "Backup"
 # done Your backup on r2d2 is over, and the log file is attached"

Checking logs whether mail was sent successfully:

tac /var/log/mail.info | less

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Fixing sendmail configuration

I found the following errors after installing sendmail:

apt-get install sendmail:

Errors in generating sendmail.cf
*** ERROR: FEATURE() should be before MAILER()
*** MAILER(`local') must appear after FEATURE(`always_add_domain')*** ERROR: FEATURE() should be before MAILER()
*** MAILER(`local') must appear after FEATURE(`allmasquerade')*** ERROR: FEATURE() should be before MAILER()

Starting Mail Transport Agent (MTA): sendmail.
Setting up sensible-mda (8.14.3-9.4) ...
Setting up sendmail (8.14.3-9.4) ...

Apparently sendmail.cf located at /etc/mail/sendmail.cf is automatically generated. To fix the issue, edit /etc/mail/sendmail.mc

#grep -in FEATURE\(\`always_add_domain\'\) ./etc/mail/sendmail.mc
106:FEATURE(`always_add_domain')dnl

#grep -in MAILER ./etc/mail/sendmail.mc
100:dnl # Default Mailer setup
101:MAILER_DEFINITIONS
102:MAILER(`local')dnl
103:MAILER(`smtp')dnl

I edited the lines from #100, and switched the positions of the MAILER and FEATURE tags.

Once edited, sendmail.cf should be autoregenerated with:

sendmailconfig

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Bind9 zone templates

Here’s a full zone template:

mydomain.tld.       IN      SOA     ns1.joel.co.in. admin.mydomain.tld. (
                   2007010401           ; Serial
                         3600           ; Refresh [1h]
                          600           ; Retry   [10m]
                      1814400           ; Expire  [1d]
                          600 )         ; Negative Cache TTL [1h]
;
mydomain.tld.     IN      NS      ns1.joel.co.in.
mydomain.tld.      IN      NS      ns2.joel.co.in.
mydomain.tld.      IN      NS      ns3.joel.co.in.
mydomain.tld.     IN      A       198.23.228.223
www.mydomain.tld. IN      A       198.23.228.223
ns1.joel.co.in.           IN      A       199.188.75.23
ns2.joel.co.in.           IN      A       38.114.103.106
ns3.joel.co.in.           IN      A       38.127.98.233
mail.mydomain.tld.        3600    IN      CNAME   ghs.google.com.
*.mydomain.tld.   3600    IN      CNAME   mydomain.tld.
mydomain.tld.      IN      MX      10 aspmx.l.google.com.
mydomain.tld.      IN     MX      20 alt1.aspmx.l.google.com.
mydomain.tld.      IN      MX      20 alt2.aspmx.l.google.com.
mydomain.tld.      IN     MX      30 aspmx2.googlemail.com.
mydomain.tld.      IN     MX      30 aspmx3.googlemail.com.
mydomain.tld.      IN     MX      30 aspmx4.googlemail.com.

Note that each entry terminates with a “.” (dot) unless it’s an ip address. Note the blank line on the last line.

Take care to replace the ips with those of yours.

The additional part required for Gapps is:

mydomain.tld.      IN      MX      10 aspmx.l.google.com.
mydomain.tld.      IN     MX      20 alt1.aspmx.l.google.com.
mydomain.tld.      IN      MX      20 alt2.aspmx.l.google.com.
mydomain.tld.      IN     MX      30 aspmx2.googlemail.com.
mydomain.tld.      IN     MX      30 aspmx3.googlemail.com.
mydomain.tld.      IN     MX      30 aspmx4.googlemail.com.

Without Gapps, it is:

mydomain.tld.       IN      SOA     ns1.joel.co.in. admin.mydomain.tld. (
                   2007010401           ; Serial
                         3600           ; Refresh [1h]
                          600           ; Retry   [10m]
                      1814400           ; Expire  [1d]
                          600 )         ; Negative Cache TTL [1h]
;
mydomain.tld.     IN      NS      ns1.joel.co.in.
mydomain.tld.      IN      NS      ns2.joel.co.in.
mydomain.tld.      IN      NS      ns3.joel.co.in.
mydomain.tld.     IN      A       198.23.228.223
www.mydomain.tld. IN      A       198.23.228.223
ns1.joel.co.in.           IN      A       199.188.75.23
ns2.joel.co.in.           IN      A       38.114.103.106
ns3.joel.co.in.           IN      A       38.127.98.233
mail.mydomain.tld.        3600    IN      CNAME   ghs.google.com.
*.mydomain.tld.   3600    IN      CNAME   mydomain.tld.

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Making sudo ask for the root password

I was using OpenSUSE at my workplace and needed to add myself to the sudoers group. I did that successfully, but the first time I tried to use sudo, I found that the system was asking for the root password instead of my password as happens in Ubuntu.

The reason was the following line in the sudoers file (/etc/sudoers):

Defaults rootpw

This means that all sudo functions require the root password, instead of the user password

You can set this only for one user, with:

Defaults:jim rootpw

Here, only jim will be asked for root password.

Note that the proper way of editing the sudoers file is by running the following command:

visudo

Sudo settings may be viewed by the following command:

sudo -V

 

#sudo -V
Sudo version 1.7.4p4

Configure args: --prefix=/usr -v --with-all-insults --with-devel --with-pam --with-fqdn --with-logging=syslog --with-logfac=authpriv --with-env-editor --with-editor=/usr/bin/editor --with-timeout=15 --with-password-timeout=0 --with-passprompt=[sudo] password for %p:  --with-timedir=/var/lib/sudo --disable-root-mailer --disable-setresuid --with-sendmail=/usr/sbin/sendmail --mandir=/usr/share/man --libexecdir=/usr/lib/sudo --with-secure-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
Sudoers path: /etc/sudoers
Authentication methods: 'pam'
Syslog facility if syslog is being used for logging: authpriv
Syslog priority to use when user authenticates successfully: notice
Syslog priority to use when user authenticates unsuccessfully: alert
Send mail if the user is not in sudoers
Use a separate timestamp for each user/tty combo
Lecture user the first time they run sudo
Require users to authenticate by default
Root may run sudo
Allow some information gathering to give useful error messages
Require fully-qualified hostnames in the sudoers file
Visudo will honor the EDITOR environment variable
Set the LOGNAME and USER environment variables
Length at which to wrap log file lines (0 for no wrap): 80
Authentication timestamp timeout: 15.0 minutes
Password prompt timeout: 0.0 minutes
Number of tries to enter a password: 3
Umask to use or 0777 to use user's: 022
Path to mail program: /usr/sbin/sendmail
Flags for mail program: -t
Address to send mail to: root
Subject line for mail messages: *** SECURITY information for %h ***
Incorrect password message: Sorry, try again.
Path to authentication timestamp dir: /var/lib/sudo
Default password prompt: [sudo] password for %p:
Default user to run commands as: root
Value to override user's $PATH with: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
Path to the editor for use by visudo: /usr/bin/editor
When to require a password for 'list' pseudocommand: any
When to require a password for 'verify' pseudocommand: all
File containing dummy exec functions: /usr/lib/sudo/sudo_noexec.so
File descriptors >= 3 will be closed before executing a command
Reset the environment to a default set of variables
Environment variables to check for sanity:
        TERM
        LINGUAS
        LC_*
        LANGUAGE
        LANG
        COLORTERM
Environment variables to remove:
        RUBYOPT
        RUBYLIB
        PYTHONUSERBASE
        PYTHONINSPECT
        PYTHONPATH
        PYTHONHOME
        TMPPREFIX
        ZDOTDIR
        READNULLCMD
        NULLCMD
        FPATH
        PERL5DB
        PERL5OPT
        PERL5LIB
        PERLLIB
        PERLIO_DEBUG
        JAVA_TOOL_OPTIONS
        SHELLOPTS
        GLOBIGNORE
        PS4
        BASH_ENV
        ENV
        TERMCAP
        TERMPATH
        TERMINFO_DIRS
        TERMINFO
        _RLD*
        LD_*
        PATH_LOCALE
        NLSPATH
        HOSTALIASES
        RES_OPTIONS
        LOCALDOMAIN
        PS4
        SHELLOPTS
        CDPATH
        IFS
Environment variables to preserve:
        XAUTHORIZATION
        XAUTHORITY
        TZ
        PS2
        PS1
        PATH
        LS_COLORS
        KRB5CCNAME
        HOSTNAME
        DISPLAY
        COLORS
Locale to use while parsing sudoers: C
Compress I/O logs using zlib

 

The following is a very useful beginner’s guide to sudoers:

http://www.developertutorials.com/tutorials/linux/using-sudo-050511-1194/


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Receiving mail on ispconfig – Debian

Stop and Remove sendmail, with apt-get. Find the package with apt-cache search

Start postfix /etc/init.d/postfix start

Check the postconf mydestination value with:

postconf -n

The issue was that mydestination included my hostname. Apparently you cant have sender and destination same.

So set the value, by:

postconf -e "destination=...." (the other values)

Now, on retrying a mail send, it gets received/


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Alert by email when root user logins by shell

The following command added to ~/.bash_profile will alert a specified address when a root user signs in.

echo 'ALERT - Root Shell Access () on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" [email protected]
source .bashrc

.bashrc is sourced because, at least on Debian squeeze, .bashrc isnt executed if .bash_profile exists.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Php send mail example

The following script sends mail.

<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");

// Send
mail([email protected]', 'My Subject', $message);
print('Executed mail function');
?>

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Send mail from a bash script

Modify and use the following script:

#!/bin/bash
# script to send simple email 
# email subject
SUBJECT="SET-EMAIL-SUBJECT"
# Email To ?
EMAIL="[email protected]"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.