Archive for the ‘Uncategorized’ Category

Postfix SSL GMail SMTP Relay on Fedora (or CentOS)

Thursday, December 3rd, 2009

The original directions for this came from here. I’ve only modified them for a clean build of a Fedora based server or box. They should work for Ubuntu, SUSE, etc if you have created a Certificate Authority already.

  1. Make sure you’ve installed postfix and removed sendmail:

    # yum install postfix
    # yum remove sendmail
  2. Make sure postfix has been built with the necessary dependencies (both commands below should return something, if not, then you will need a different version of postfix):

    # ldd `which postfix` | grep libsasl
    # ldd `which postfix` | grep libssl
  3. Make sure openssl and openssl-perl are installed so we can generate certificates and create SSL connections to GMail

    # yum install openssl openssl-perl
  4. Need to create a Certificate Authority (if you don’t already have one):

    # cd /etc/pki/tls/misc
    # ./CA.pl -newca

    You will be prompted for the file name (just hit Enter). Then you will be asked for a PEM pass phrase, which you need to remember. You can fill out the Country Name, State or Province Name, Locality Name, Organization Name, and Organizational Unit Name to your liking (or take the defaults). You need to remember the Organization Name (if you changed it) as it must match one in a key we create later. For the Common Name, fill in “CA” (without quotes). Take defaults for everything else and when prompted to enter the pass phrase you need to enter the same one you did above.
  5. Create a client key that is sent to GMail to start the SSL encryption:

    # cd /etc/pki/tls
    # mkdir gmail_relay
    # cd gmail_relay
    # openssl genrsa -out server.key 1024
    # openssl req -new -key server.key -out server.csr
    # openssl ca -out server.pem -infiles server.csr

    The second openssl command above will prompt you for the Country, State, Locality, etc parameters again. The only value that has to match what was entered for the Certificate Authority is the Organization Name. For the Common Name you should put your server name (fully qualified preferred, but does not really matter). The last command will prompt you for your CA pass phrase that you used earlier. When asked if you want to Sign the certificate, say yes. also when asked if you should commit it, say yes.
  6. Add the following to the bottom of the file /etc/postfix/main.cf. The last setting for any option is the one that is saved, so anything above this will not be affect these final settings:

    #### GMail SSL SMTP Relay
    relayhost = [smtp.gmail.com]:587

    #auth
    smtp_sasl_auth_enable=yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

    #tls
    smtp_use_tls = yes
    smtp_sasl_security_options = noanonymous
    smtp_sasl_tls_security_options = noanonymous
    smtp_tls_note_starttls_offer = yes
    tls_random_source = dev:/dev/urandom
    smtp_tls_scert_verifydepth = 5
    smtp_tls_key_file=/etc/pki/tls/gmail_relay/server.key
    smtp_tls_cert_file=/etc/pki/tls/gmail_relay/server.pem
    smtpd_tls_ask_ccert = yes
    smtpd_tls_req_ccert =no
    smtp_tls_enforce_peername = no

  7. Create /etc/postfix/sasl_passwd file with your GMail login credentials that looks like below:

    gmail-smtp.l.google.com user@gmail.com:password
    smtp.gmail.com user@gmail.com:password

    Obviously, you need to change user to your username and password to your gmail password.
  8. Protect the files with your GMail login data:

    # chmod o-r /etc/postfix/sasl_passwd
    # chmod o-r /etc/postfix/sasl_passwd.db
    # chown postfix /etc/postfix/sasl_passwd
    # chown postfix /etc/postfix/sasl_passwd.db
  9. Restart Postfix and enjoy having your email from your server sent through your GMail account:

    # /etc/init.d/postfix restart

Create Ubuntu Apt Mirror on CentOS Server

Wednesday, June 24th, 2009

So I run an internal CentOS server that contains a complete mirror of the CentOS repositories that we use for all our servers at work.  This saves a lot of time/bandwidth as the local mirror syncs itself with the outside world once a day (around midnight) and all the local servers point at the local mirror for installs or updates.  Well, we also have a lot of Ubuntu desktops so I wanted to use the same machine to also create a local Ubuntu repository. The tool of choice for this job is apt-mirror. I couldn’t find an RPM (and my initial attempt at downloading the source and building was missing some prerequisites and had issues) so I figured, why not use Ubuntu to create an Ubuntu repository. I didn’t want to have a machine dedicated to this purpose, so in comes my favorite tool for Debian/Ubuntu systems: debootstrap.  Fortunately, there is an RPM for debootstrap for FC10, but since it only relies on Python it can be downloaded and installed directly into CentOS 5.2.  So to get a base Ubuntu install created do the following steps (at this time the highest release in Fedora’s RPM is intrepid, but that will work for our purposes):

  1. Download debootstrap RPM it is the same for i386 and X86_64 systems.
  2. # rpm -ivh debootstrap-1.0.10-1.fc10.noarch.rpm
  3. # mkdir /chroot
  4. # deboostrap --arch (amd64 or i386) intrepid /chroot/ubuntu-8.10
  5. # chroot /chroot/ubuntu-8.10
  6. (inside-chroot)# apt-get update
  7. #apt-get install apt-mirror