Showing posts with label LDAP. Show all posts
Showing posts with label LDAP. Show all posts

Monday, February 15, 2016

LDAP Configuration(On Debian)

LDAP .
            LDAP stands for Lightweight Directory Access Protocol.

Reference. Google is the best reference for any kind of  problem & also for LDAP :)

LDAP Installation.
                        when you are going to install ldap in your are syetm than you must have extra
packages installed for ldap.
For Example.  Apache2 , PHP5

Apache Installation.
apt-get install apache2
For server-side, HTML-embedded scripting languag supports u have to install  libapache2-mod-php5 & also apache2-utils it's a utility programs for webservers.


PHP Installation
apt-get install php5
and php5-common for  Common files for packages built from the php and php5-ldap  it's  LDAP module for php5.

After Installion of apache2 and php5 u have to check them either both r working or not.
Apache testing.
on the webbrowser type http://localhost
It will return u a index.html page but if it's did't it mean there is some problem in ur apache2.

Php testing.
you have to make a php file for cheching php kit it's working or not
Make a php file name test.php
#] vi /var/www/test.php
write some php code or this code is batter for testing
<?php  phpinfo(); ?>

Now type this on webbrowser http://localhost/test.php
phpinfo method will return u a complete informationa about php thats installed in ur system.

LDAP Installation
apt-get install slapd it's a OpenLDAP server (slapd).

After installation there is two most important and editable files
/etc/ldap/slapd.con  (for server configuration)
/etc/ldap/ldap.con  (for client configuration)

when u r going to edit slapd.conf than first make backup for that file.Now you have to change little bit in the configuration file opn it in vi or any other editor.

vi /etc/ldap/slapd.conf
Add suffix it's base of your directory in database
suffix          "dc=imtiaz,dc=emergen,dc=org"


also u have to change and add some attributes.
access to attrs=userPassword
        by dn="cn=admin,dc=imtiaz,dc=emergen,dc=org" write
        by anonymous auth
        by self write
        by * none
The userPassword by default can be changed  by the entry owning it if they are authenticated.
Others should not be able to see it, except the admin entry below.a These access lines apply to database #1 only

or if u feel difficult to edit this file or u don't want to to that than u can configure with the
help of command

dpkg-reconfigure slapd
Add the suffic(i.e. dc=imtiaz,dc=emergen,dc=org) and company name (i.e. Emergen Consulting) and ldap root password. If u select all the option defalut than batter or i u want to set according to ur requirement than u can read and make changes :)

If u wana know about ldap is working or not thats u can check with the builtin command
called
slapdtest
There is a lot of commads they can help u to know about ldap.

Now its time to install phpldapadmin its' web based interface for administering LDAP servers
u can install with the help of
apt-get install phpldapadmin
else  if u have a .gz file also u can extract that.
when u complete ur installation or extrection than there is one configuration file called config.php its available in ../phpldapadmin/config/config.php edit that file.
vi ../phpldapadmin/config/config.php

Before > $ldapservers->SetValue($i,'server','name','My LDAP Server');
After   < $ldapservers->SetValue($i,'server','name','Imtiaz Directory Service');

Before > // $ldapservers->SetValue($i,'server','host','127.0.0.1');
After   < $ldapservers->SetValue($i,'server','host','localhost');

Bwfore > // $ldapservers->SetValue($i,'server','port','389');
After    < $ldapservers->SetValue($i,'server','port','389');




Before > // $ldapservers->SetValue($i,'server','base',array(''));
After   < $ldapservers->SetValue($i,'server','base',array('dc=imtiaz,dc=emergen,dc=org'));

Before > // $ldapservers->SetValue($i,'server','auth_type','cookie');
After < $ldapservers->SetValue($i,'server','auth_type','session');

Before >#  $ldapservers->SetValue($i,'login','dn','cn=Manager,dc=example,dc=com');
After  < $ldapservers->SetValue($i,'login','dn','cn=admin,dc=imtiaz,dc=emergen,dc=org');

Before >  $ldapservers->SetValue($i,'login','pass','secret');
After   < $ldapservers->SetValue($i,'login','pass','emergen');

After change this now it's time to run the phpldapadmin
type this on the web browser
u'll see a phpldapadmin login page on the web browser than login & use who ever u want to use and create what ever u what to create :)

Login DN : cn=admin,dc=imtiaz.dc=emergen,dc=org
 [cn,dc that's u added in phpldapadmin config.php file]
Password  : emergen
[what ever password u was given on phpldapadmin config file.]

Note:- if ur ladp is not aceepting the login dn or password than it's batter to run
dpkg-reconfigure slapd.

When u finished to create  groups & also users than now it's time to check them either they r
completely created and u can use them, u can check that with the help of ssh but befor that u have to installed some more packages and also u have to make changes in some configuration files.

Now install
apt-get install libnss-ldap
apt-get installl libpam-ldap

After installation u have to make changes in file

vi  /etc/nsswitch.conf

passwd:  files ldap
group:   files ldap
shadow:  files ldap

vi /etc/pam.d/common-account

account sufficient      pam_unix.so
account sufficient      pam_ldap.so

vi /etc/pam.d/common-auth

auth    sufficient pam_unix.so nullok_secure
auth    sufficient pam_ldap.so use_first_pass


vi /etc/pam.d/common-password

password sufficient pam_unix.so nullok obscure min=4 max=8 md5
password sufficient pam_ldap.so use_first_pass debug


vi /etc/pam.d/common-session

session required        pam_unix.so
session optional        pam_foreground.so
session sufficient      pam_ldap.so

After editing all these files try to make ssh with ur added user.
if u want to check ur added user's than u can check with

#] getent passwd
It'll show u all the ldap added user's.



if ur successful login than ur ldap is working fine  :)

Postfix , Dovecot and Its Integration with LDAP

Postfix is a very popular mail server . It is robust and easy to setup . It acts as a MTA ( mail transfer agent ) that can receive your mail and drop it into a local mailbox .

How to configure postfix:

The packages required to install postfix are postfix , postfix-ldap , postfix -pcre .
#apt-get install postfix postfix-pcre  postfix-ldap

The first configuration file for postfix is /etc/postfix/main.cf
#vi /etc/postfix/main.cf

# See /usr/share/postfix/main.cf.dist for a commented, more complete version

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${queue_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${queue_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = asim.emergen.org
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = asim.emergen.org, , localhost
relayhost =
mynetworks = 127.0.0.0/8 192.168.1.0
mailbox_size_limit = 0
mailbox_transport = dovecot
recipient_delimiter = +
inet_interfaces = all

The second configuration for postfix is /etc/mailname . Here we define the fully qualified domain name .
#vi /etc/mailname
asim.emergen.org

The third file is /etc/postfix/master.cf
smtp      inet  n       -       n       -       -       smtpd
pickup    fifo  n       -       -       60      1       pickup
cleanup   unix  n       -       -       -       0       cleanup
qmgr      fifo  n       -       -       300     1       qmgr
#qmgr     fifo  n       -       -       300     1       oqmgr
rewrite   unix  -       -       -       -       -       trivial-rewrite
bounce    unix  -       -       -       -       0       bounce
defer     unix  -       -       -       -       0       bounce
trace     unix  -       -       -       -       0       bounce
verify    unix  -       -       -       -       1       verify
flush     unix  n       -       -       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
smtp      unix  -       -       n       -       -       smtp
relay     unix  -       -       -       -       -       smtp
showq     unix  n       -       -       -       -       showq
error     unix  -       -       -       -       -       error
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       n       -       -       lmtp
anvil     unix  -       -       n       -       1       anvil

dovecot   unix  -       n       n       -       -       pipe
 flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient}
mailman unix  -       n       n       -       -       pipe
 flags=FR user=list
 argv=/var/lib/mailman/bin/postfix-to-mailman.py ${nexthop} ${user}
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/opt/maildrop/bin/maildrop -d ${recipient}
uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -d -t$nexthop -f$sender $recipient
scalemail-backend unix  -       n       n       -       2       pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
gnarwl    unix  -       n       n       -       -       pipe
  flags=F user=vmail argv=/usr/bin/gnarwl -a $user
smtp-amavis  unix   -    -    n   -    2 lmtp
 -o smtp_data_done_timeout=1200
 -o disable_dns_lookups=yes
 -o smtp_send_xforward_command=yes

127.0.0.1:10025  inet  n - n - - smtpd
 -o content_filter=
 -o local_recipient_maps=
 -o relay_recipient_maps=
 -o smtpd_restriction_classes=
 -o smtpd_client_restrictions=
 -o smtpd_helo_restrictions=
 -o smtpd_sender_restrictions=
 -o smtpd_recipient_restrictions=permit_mynetworks,reject
 -o mynetworks=127.0.0.0/8
 -o strict_rfc821_envelopes=yes

After this , start the service
#/etc/init.d/postfix start

 To verify whether postfix is working correctly 
#telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 asim.emergen.org ESMTP Postfix (Ubuntu)

Dovecot

Dovcecot acts as an MDA ( mail delivery agent ) .It handles final delivery of messages for a system's local recipients .

The package required to install dovecot is dovecot – common , dovecot – pop3d and dovecot – imapd .
#apt-get install dovecvot-common dovecot-pop3d dovecot-imapd

The main configuration file is
#vi /etc/dovecot/dovecot.conf
protocols = imap imaps pop3 pop3s

#ssl_disable = no
#ssl_cert_file = /etc/postfix/tls/server.pem
#ssl_key_file = /etc/postfix/tls/key.pem

log_timestamp = "%Y-%m-%d %H:%M:%S "

#login_greeting = Dovecot ready.
#max_mail_processes = 1024

mail_extra_groups = vmail
#mail_debug = yes

default_mail_env = maildir:%h:INDEX=/var/dovecot/indexes/%h
disable_plaintext_auth = no

protocol imap {
 # mail_plugins = quota imap_quota
#  mail_plugin_dir = /usr/lib/dovecot/modules/imap
}

protocol pop3 {
  pop3_uidl_format = %08Xu%08Xv
 # mail_plugins = quota
 # mail_plugin_dir = /usr/lib/dovecot/modules/pop3
}

protocol lda {
 # mail_plugins = quota
 # mail_plugin_dir = /usr/lib/dovecot/modules/imap
  postmaster_address = postmaster@emergen.org
  auth_socket_path = /var/run/dovecot-auth-master
  log_path = /var/log/dovecot-deliver.log
  info_log_path = /var/log/dovecot-deliver.log
}

auth default {
  mechanisms = plain

  socket listen {
     master {
protocols = imap imaps pop3 pop3s

#ssl_disable = no
#ssl_cert_file = /etc/postfix/tls/server.pem
#ssl_key_file = /etc/postfix/tls/key.pem

log_timestamp = "%Y-%m-%d %H:%M:%S "

#login_greeting = Dovecot ready.
#max_mail_processes = 1024

mail_extra_groups = vmail
#mail_debug = yes

default_mail_env = maildir:%h:INDEX=/var/dovecot/indexes/%h
disable_plaintext_auth = no

protocol imap {
 # mail_plugins = quota imap_quota
#  mail_plugin_dir = /usr/lib/dovecot/modules/imap
}

protocol pop3 {
  pop3_uidl_format = %08Xu%08Xv
 # mail_plugins = quota
 # mail_plugin_dir = /usr/lib/dovecot/modules/pop3
}

protocol lda {
 # mail_plugins = quota
 # mail_plugin_dir = /usr/lib/dovecot/modules/imap
  postmaster_address = postmaster@emergen.org
  auth_socket_path = /var/run/dovecot-auth-master
  log_path = /var/log/dovecot-deliver.log
  info_log_path = /var/log/dovecot-deliver.log
}

auth default {
  mechanisms = plain

  socket listen {
     master {
  path = /var/run/dovecot-auth-master
       mode = 0600
       user =  vmail # User running Dovecot LDA
     }
   }

  passdb pam {
  }

  # LDAP database
  userdb ldap {
    args = /etc/dovecot/dovecot-ldap.conf
  }

  user = vmail
}

plugin {
  # Default quota for all users is set to 100 MB with a
  # limit of 5000 messages in Mailbox.
 # quota = maildir:storage=102400:messages=500
}
                                                                                                           64,1          Bot
The second configuration file is
#vi /etc/dovecot/dovecot-ldap.conf

hosts = asim.emergen.org
ldap_version = 3
base = ou=people,dc=asim,dc=emergen,dc=org
scope = subtree
user_attrs = uid,mailMessageStore,,,,,mailQuotaSize=quota
user_filter = (&(&(objectClass=qmailUser)(accountStatus=active))(|(mailAlternateAddress=%u)(mail=%u)(uid=%u)))
user_global_uid = 1005
user_global_gid = 1005

Now, we have to define the authentication type in the file /etc/default/saslauthd .

#vi /etc/default/saslauthd

Zimbra- Debian

It's batter to configure bind9 (DNS) before installing zimbra.

            First let's install some prerequisites for Zimbra
                        # apt-get install perl curl fetchmail libpcre3 libgmp3 libexpat1 libxml2
                        libtie-ixhash-perl sudo libc6-i686 openssl libstdc++6

            Afterwards, unpack the Zimbra .tgz file and start the installer:

                        # tar -xvf zcs-4.5.6_GA_1044.DEBIAN3.1.tgz
                        # cd zcs/
                        # ./install.sh

            The installer will ask a few questions. Answer them like this:

            Operations logged to /tmp/install.log.4416
            Checking for existing installation...
                            zimbra-ldap...NOT FOUND
                            zimbra-logger...NOT FOUND
                            zimbra-mta...NOT FOUND
                            zimbra-snmp...NOT FOUND
                            zimbra-store...NOT FOUND
                            zimbra-apache...NOT FOUND
                            zimbra-spell...NOT FOUND
                            zimbra-core...NOT FOUND


            PLEASE READ THIS AGREEMENT CAREFULLY BEFORE USING THE SOFTWARE.
            ZIMBRA, INC. ("ZIMBRA") WILL ONLY LICENSE THIS SOFTWARE TO YOU IF YOU
            FIRST ACCEPT THE TERMS OF THIS AGREEMENT. BY DOWNLOADING OR             INSTALLING            THE SOFTWARE, OR USING THE PRODUCT, YOU ARE CONSENTING TO       BE BOUND BY THIS AGREEMENT. IF YOU DO NOT AGREE TO ALL OF THE TERMS OF             THIS AGREEMENT, THEN DO NOT DOWNLOAD, INSTALL OR USE THE PRODUCT.

                        License Terms for the Zimbra Collaboration Suite:
                        http://www.zimbra.com/license/collaboration_suite_collective_license_1.0.html

                        Press Return to continue <-- <ENTER>


                        Install zimbra-ldap [Y] <-- <ENTER>
           
                        Install zimbra-logger [Y] <-- <ENTER>

                        Install zimbra-mta [Y] <-- <ENTER>

                        Install zimbra-snmp [Y] <-- <ENTER>

                        Install zimbra-store [Y] <-- <ENTER>

                        Install zimbra-spell [Y] <-- <ENTER>

                        The system will be modified.  Continue? [N] <-- y


                        Main menu

                           1) Hostname:                                    mail.example.com
                           2) Ldap master host:                        mail.example.com
                           3) Ldap port:                                    389
                           4) Ldap password:                           set
                           5) zimbra-ldap:                                 Enabled
                           6) zimbra-store:                                Enabled
                                +Create Admin User:                  yes
                                +Admin user to create:                admin@mail.example.com
                        ******            +Admin Password                        UNSET
                                +Enable automated spam training:       yes
                                +Spam training user:                               spam.tukjrdnaco@mail.example.com
                                +Non-spam(Ham) training user:              ham.rg8fvq6cd4@mail.example.com
                                +Global Documents Account:                  wiki@mail.example.com
                                +SMTP host:                                           mail.example.com
                                +Web server HTTP port:                         80
                                +Web server HTTPS port:                      443
                                +Web server mode:                                 http
                                +Enable POP/IMAP proxy:                    no
                                +IMAP server port:                     143
                                +IMAP server SSL port:                          993
                                +POP server port:                                    110
                                +POP server SSL port:                            995
                                +Use spell check server:                          yes
                                +Spell server URL:                                 http://mail.example.com:7780/aspell.php

                           7) zimbra-mta:                                  Enabled
                           8) zimbra-snmp:                               Enabled
                           9) zimbra-logger:                              Enabled
                          10) zimbra-spell:                                Enabled
                           r) Start servers after configuration        yes
                           s) Save config to file
                           x) Expand menu
                           q) Quit

                        Address unconfigured (**) items  (? - help) <-- 6

                                                Store configuration

                           1) Status:                                          Enabled
                           2) Create Admin User:                     yes
                           3) Admin user to create:                   admin@mail.example.com
                        ** 4) Admin Password                        UNSET
                           5) Enable automated spam training:          yes
                           6) Spam training user:                      spam.tukjrdnaco@mail.example.com
                           7) Non-spam(Ham) training user:                 ham.rg8fvq6cd4@mail.example.com
                           8) Global Documents Account:                    wiki@mail.example.com
                           9) SMTP host:                                              mail.example.com
                          10) Web server HTTP port:                           80
                          11) Web server HTTPS port:                         443
                          12) Web server mode:                                   http
                          13) Enable POP/IMAP proxy:                      no
                          14) IMAP server port:                                   143
                          15) IMAP server SSL port:                            993
                          16) POP server port:                                      110
                          17) POP server SSL port:                              995
                          18) Use spell check server:                            yes
                          19) Spell server URL:                                   http://mail.example.com:7780/aspell.php

                        Select, or 'r' for previous menu [r] <-- 4



                        Password for admin@mail.example.com (min 6 characters): [8BD.yZtFh] <-- [specify a                             password for the admin user, e.g. howtoforge]

                        Select, or 'r' for previous menu [r] <-- <ENTER>

                        Main menu

                           1) Hostname:                                    mail.example.com
                           2) Ldap master host:                        mail.example.com
                           3) Ldap port:                                    389
                           4) Ldap password:                           set
                           5) zimbra-ldap:                                 Enabled
                           6) zimbra-store:                                Enabled
                           7) zimbra-mta:                                  Enabled
                           8) zimbra-snmp:                               Enabled
                           9) zimbra-logger:                              Enabled
                          10) zimbra-spell:                                Enabled
                           r) Start servers after configuration   yes
                           s) Save config to file
                           x) Expand menu
                           q) Quit

                        *** CONFIGURATION COMPLETE - press 'a' to apply
                        Select from menu, or press 'a' to apply config (? - help) <-- a
                        Save configuration data to a file? [Yes] <-- <ENTER>
                        Save config in file: [/opt/zimbra/config.5762] <-- <ENTER>
                        Saving config in /opt/zimbra/config.5762...Done
                        The system will be modified - continue? [No] <-- y

                        You have the option of notifying Zimbra of your installation.
                        This helps us to track the uptake of the Zimbra Collaboration Suite.
                        The only information that will be transmitted is:
                                The VERSION of zcs installed (zcs-4.5.6_GA_1044.DEBIAN3.1)
                                The ADMIN EMAIL ADDRESS created (admin@mail.example.com)

                        Notify Zimbra of your installation? [Yes] <-- [if you want to notify Zimbra of your                           installation, type y, otherwise n]

                        Configuration complete - press return to exit <-- <ENTER>
           
                        That's it already. To test if all Zimbra services are running, become the zimbra user:

                                    # su  zimbra

                        and run
           
                                    # zmcontrol status

                        The output should look like this:

                        zimbra@mail:~$ zmcontrol status
                                    Host mail.example.com
                                            antispam               Running
                                            antivirus               Running
                                            ldap                      Running
                                            logger                   Running
                                            mailbox                Running
                                            mta                       Running
                                            snmp                     Running
                                            spell                      Running

                        If not all services are started, run

                                    # zmcontrol start
                        Type exit
                       
                        Access from the browser.
                                    for user  -->     http://ipaddress
                                    for administrator --> https://ipaddress:7170

                        Adding user's through command
                                    # su zimbra
                                    zmprov ca [username@domain] [password]   [attribute] [value] [attribute] [value]

                                    # zmprov ca imtiaz@mail.emergen.org imtiaz           
           



                        You can also add the user's from a file
                                    # vi  zimbrausers
                                   
                                      ca user1 user1pass
                      ca user2 user2pass
                      ca user3 user3pass
                      ca adminuser adminuserpass zimbraIsAdminAccount TRUE
                      ca user4 user4pass zimbraMailAlias user_4 zimbraMailAlias                                                     user_four zimbraMailAlias user.four
                      ca nopassuser
                        Save a file and run
                                    # zmprov < zimbrausers
                       
            Configuring external LDAP Authentication

            LDAP Filter:
                        [http://wiki.zimbra.com/index.php?title=LDAP_Authentication]
                        To set the LDAP query filter, you will need a substitution variable and an attribute on the                            external LDAP server to search. The substitution variable is obtained from the 'Username'                           box on the user login page. Possible substitution variables are (e.g., usera@domain.com):   
                       
                        %n = username with @ symbol - returns 'usera@domain.com'
     %u = username without the @ - returns 'usera'
     %d = domain - returns 'domain.com'
     %D = domain as dc=domain,dc=com - this is a common format for directories such as                     Active Directory and OpenLDAP
                       
                        Example:
                                    Possible filters for ldap.
                                    uid=%u

            LDAP Base Search.

                        o=corp - Exchange 5.5
                        o=corp,c=us - Lotus Domino
                        dc=domain,dc=com - Active Directory, OpenLDAP
                        ou=Mail Users,dc=domain,dc=com - Active Directory restricting to "Mail Users"                                                                                     organizational unit.
http://www.howtoforge.com/perfect_setup_xen3_debian_p4?s=6fb984c03076b8510d78e22ad3a09c48&
http://www.howtoforge.com/installing_zimbra_collaboration_suite_on_ubuntu


AWS EC2 - SSH locked with UFW

Need to update the instance's user data: 1. Stop the instance 2. Right click (windows) or ctrl + click (Mac) on the instance to open a c...