How make a Linux FTP server with Active Directory authentication.

Jump to: navigation, search

We need to installing and configuring Kerberos, Samba, and Winbind on Ubuntu Server


Step 1: Install the Required Packages

Note: Enter Y when asked if you want to install the additional packages

sudo apt-get update                     (good idea)
sudo apt-get upgrade (good idea)
sudo apt-get install build-essentials (good idea)
sudo apt-get install krb5-user
sudo apt-get install winbind
sudo apt-get install samba
sudo apt-get install proftpd
sudo apt-get install proftpd-ldap
sudo apt-get install proftpd-doc (good idea)


Install in the Windows Domain Controller the Windows Services for UNIX Version 3.5


Step 2: Edit the /etc/krb5.conf File

[libdefaults]
default_realm = YOUR.DOMAIN
# default_tkt_enctypes = des3-hmac-sha1 des-cbc-crc
# default_tgs_enctypes = des3-hmac-sha1 des-cbc-crc

[realms]
RRDTV.LOCAL = {
kdc = name.your.domain
admin_server = name.your.domain
default_domain = YOUR.DOMAIN
}

[domain_realm]
.your.domain = YOUR.DOMAIN
your.domain = YOUR.DOMAIN

[login]
krb4_convert = true
krb4_get_tickets = false


Step 3: Edit /etc/samba/smb.conf

1) Make the edits. The configuration shown is the bare minimum and doesn't share anything.

[global]
security = ads
realm = YOUR.DOMAIN
password server = name.your.domain
workgroup = YOUR
idmap uid = 500-10000000
idmap gid = 500-10000000
winbind separator = /
winbind enum users = no
winbind enum groups = no
winbind use default domain = yes
template homedir = /home/%D/%U
template shell = /bin/bash
client use spnego = yes
domain master = no

[shared folder]
comment=shared folder
path=/home/RRDTV/dmt/
browseable = yes
read only = no
inherit acls = yes
inherit permissions = yes
create mask = 777
directory mask = 777
valid users = @"YOUR/Domain Users"
admin users = @"YOUR/Domain Admins"

2) Test the configuration with the testparm command


Step 4: Edit /etc/nsswitch.conf to look like the example below

# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd: compat winbind
group: compat winbind
shadow: compat winbind

hosts: files dns wins
networks: files

protocols: db files
services: db files
ethers: db files
rpc: db files

netmask: files
netgroup: nis
bottparams: files

automount: files
aliases: files


Step 5: Modify the PAM settings

1) /etc/pam.d/common-account should contain only the following lines


account sufficient	pam_winbind.so
account required pam_unix.so


2) /etc/pam.d/common-auth should contain only the following lines

auth    sufficient      pam_winbind.so
auth required pam_unix.so nullok_secure use_first_pass


3) Modify the /etc/pam.d/common-password file, so the max parameter is set to 50, similar to the one shown below

password   required   pam_unix.so nullok obscure min=4 max=50 md5


4) Make sure the /etc/pam.d/common-session file contains the following line

session required        pam_mkhomedir.so umask=000 skel=/etc/skel


Step 6: Make a directory to hold domain user home directories

Note: Use the value you put in the WORKGROUP tag of the /etc/samba/smb.conf file

mkdir /home/USERS


Step 7: Initialize Kerberos

1)
kinit domain-controller_admin_account@YOUR.DOMAIN

Next check to be sure you got a ticket from the domain controller

2)
klist


Step 8: Join the system to the

net ads join -U domain-controller_admin_account@YOUR.DOMAIN


'''Step 9: Restart Samba-related Services (Or reboot the server)'''

Note: ''The order is important''

<pre>
/etc/init.d/samba stop
/etc/init.d/winbind stop
/etc/init.d/samba start
/etc/init.d/winbind start


TESTING Active Directory DATA BIND with
wbinfo -u


Now is the time of ProFTP Server.


Edit: /etc/proftpd/proftpd.conf


# Includes DSO modules
Include /etc/proftpd/modules.conf

# Set off to disable IPv6 support which is annoying on IPv4 only boxes.
UseIPv6 off

ServerName "FTP Server"
ServerType standalone
DeferWelcome off

MultilineRFC2228 on
DefaultServer on
ShowSymlinks on

TimeoutNoTransfer 600
TimeoutStalled 600
TimeoutIdle 1200

DisplayLogin welcome.msg
DisplayFirstChdir .message
ListOptions "-l"

DenyFilter \*.*/

# Use this to jail all users in their homes
DefaultRoot ~

# Users require a valid shell listed in /etc/shells to login.
# Use this directive to release that constrain.
# RequireValidShells off

# Port 21 is the standard FTP port.
Port 21

# In some cases you have to specify passive ports range to by-pass
# firewall limitations. Ephemeral ports can be used for that, but
# feel free to use a more narrow range.
# PassivePorts 49152 65534

# If your host was NATted, this option is useful in order to
# allow passive tranfers to work. You have to use your public
# address and opening the passive ports used on your firewall as well.
# MasqueradeAddress 1.2.3.4

# To prevent DoS attacks, set the maximum number of child processes
# to 30. If you need to allow more than 30 concurrent connections
# at once, simply increase this value. Note that this ONLY works
# in standalone mode, in inetd mode you should use an inetd server
# that allows you to limit maximum number of processes per service
# (such as xinetd)
MaxInstances 30

# Set the user and group that the server normally runs at.
User proftpd
Group nogroup

# Umask 022 is a good standard umask to prevent new files and dirs
# (second parm) from being group and world writable.

Umask 000 000

# Normally, we want files to be overwriteable.
AllowOverwrite off

# Uncomment this if you are using NIS or LDAP to retrieve passwords:
PersistentPasswd off

LDAPServer 172.18.0.10
LDAPUseTLS off
LDAPDNInfo cn=authuser,ou=RRD,dc=rrdtv,dc=local authuser
LDAPDoAuth on "cn=RRD,dc=rrdtv,dc=local"
LDAPAuthBinds on

# Be warned: use of this directive impacts CPU average load!
# Uncomment this if you like to see progress and transfer rate with ftpwho
# in downloads. That is not needed for uploads rates.
#
# UseSendFile off

# Choose a SQL backend among MySQL or PostgreSQL.
# Both modules are loaded in default configuration, so you have to specify the backend
# or comment out the unused module in /etc/proftpd/modules.conf.
# Use 'mysql' or 'postgres' as possible values.
#
#<IfModule mod_sql.c>
# SQLBackend mysql
#</IfModule>

TransferLog /var/log/proftpd/xferlog
SystemLog /var/log/proftpd/proftpd.log

<IfModule mod_tls.c>
TLSEngine off
</IfModule>

<IfModule mod_quota.c>
QuotaEngine on
</IfModule>

<IfModule mod_ratio.c>
Ratios on
</IfModule>


# Delay engine reduces impact of the so-called Timing Attack described in
# http://security.lss.hr/index.php?page=details&ID=LSS-2004-10-02
# It is on by default.
<IfModule mod_delay.c>
DelayEngine on
</IfModule>

<IfModule mod_ctrls.c>
ControlsEngine on
ControlsMaxClients 2
ControlsLog /var/log/proftpd/controls.log
ControlsInterval 5
ControlsSocket /var/run/proftpd/proftpd.sock
</IfModule>

<IfModule mod_ctrls_admin.c>
AdminControlsEngine on
</IfModule>

# A basic anonymous configuration, no upload directories.

# <Anonymous ~ftp>
# User ftp
# Group nogroup
# # We want clients to be able to login with "anonymous" as well as "ftp"
# UserAlias anonymous ftp
# # Cosmetic changes, all files belongs to ftp user
# DirFakeUser on ftp
# DirFakeGroup on ftp
#
# RequireValidShell off
#
# # Limit the maximum number of anonymous logins
# MaxClients 10
#
# # We want 'welcome.msg' displayed at login, and '.message' displayed
# # in each newly chdired directory.
# DisplayLogin welcome.msg
# DisplayFirstChdir .message
#
# # Limit WRITE everywhere in the anonymous chroot
# <Directory *>
# <Limit WRITE>
# DenyAll
# </Limit>
# </Directory>
#
# # Uncomment this if you're brave.
# # <Directory incoming>
# # # Umask 022 is a good standard umask to prevent new files and dirs
# # # (second parm) from being group and world writable.
# # Umask 022 022
# # <Limit READ WRITE>
# # DenyAll
# # </Limit>
# # <Limit STOR>
# # AllowAll
# # </Limit>
# # </Directory>
#
# </Anonymous>


Reboot ProFTPd server

 sudo /etc/init.d/proftpd restart


To ADD a new USER in the FTP server simply ADD it directly in the WINDOWS DOMAIN CONTROLLER RRD -> 172.18.0.10 or srv-dc.rrdtv.local

To ADD files into the FTP folder of EXTERNAL users add a shared folder of it into the /etc/samba/smb.conf

[shared folder]
comment=shared folder
path=/home/USERS/foler_name/
browseable = yes
read only = no
inherit acls = yes
inherit permissions = yes
create mask = 777
directory mask = 777
valid users = @"YOUR/Domain Users"
admin users = @"YOUR/Domain Admins"


Enjoy -- May the Force be with you -- Only the brave

By: Cubello Antonio