Ubuntu下搭建支持LDAP的proftpd服务器

背景

前几天搭建好了Gerrit和mediawiki服务器,最近有空想把自动构建Jenkins服务器搭建起来,但是前提需要一个保存镜像的地方,因此首先需要搭建要给ftp服务器,考虑到集成LDAP服务,经过调查选择了proftpd,比较了vsftpd,ftpd等后,由于proftpd支持ldap,功能也比较强大,就是配置复杂一些。

详细信息参考官网: http://www.proftpd.org

安装准备

安装Proftpd的操作过程中,会提示选择 :

 sudo apt-get install proftpd-basic

 Proftpd有两种运行模式:standalone、xinetd 

简单说经典模式主要用于接入大量用户的场景,xinetd是少量用户接入,空闲是资源占用少。

我按默认采用 standalone

因为我要用Ldap认证,还需要安装额外包

sudo apt-get install proftpd-mod-ldap

 这样安装工作就完成了,使用ubuntu的ssh 用户就可以直接登录查看

服务配置

1,ftp主目录配置

由于我们的配置是将所有用户指向一个目录

/etc/proftpd/proftpd.conf  里的DefaulRoot修改为自己的目录,其实你可以发现这个配置后,ssh用户登录只能看到此目录,其他目录包括用户主目录也不运行看了

# Use this to jail all users in their homes
DefaultRoot                     /home/ftp

2, ldap配置

需要添加ldap的模块和配置,

修改/etc/proftpd/proftpd.conf 配置

Include /etc/proftpd/ldap.conf

修改 /etc/proftpd/modules.conf

# Install proftpd-mod-ldap to use this
LoadModule mod_ldap.c

修改 /etc/proftpd/ldap.conf 

#
# Proftpd sample configuration for LDAP authentication.
#
# (This is not to be used if you prefer a PAM-based LDAP authentication)
#

<IfModule mod_ldap.c>
#
# This is used for ordinary LDAP connections, with or without TLS
#
#LDAPServer ldap://ldap.example.com
#LDAPBindDN "cn=admin,dc=example,dc=com" "admin_password"
#LDAPUsers dc=users,dc=example,dc=com (uid=%u) (uidNumber=%u)
#
# To be set on only for LDAP/TLS on ordinary port, for LDAP+SSL see below
#LDAPUseTLS on
#
LDAPLog /var/log/proftpd/ldap.log
LDAPServer example.china
LDAPBindDN DN "password"
LDAPSearchScope subtree
LDAPAttr uidNumber sAMAccountName
LDAPAttr uid name
LDAPAttr gidNumber primaryGroupID
RequireValidShell off



# Create the home directory
LDAPGenerateHomedir on
LDAPGenerateHomedirPrefix /home/ftp/
LDAPGenerateHomedirPrefixNoUsername on
LDAPUsers OU=12,DC=345,DC=CHINA (sAMAccountName=%u)
#
# This is used for encrypted LDAPS connections
#
#LDAPServer ldaps://ldap.example.com
#LDAPBindDN "cn=admin,dc=example,dc=com" "admin_password"
#LDAPUsers dc=users,dc=example,dc=com (uid=%u) (uidNumber=%u)
#
</IfModule>

说明:

1,LDAPLog  可以用来定位认证过程的log,比较有用,建议添加

2,LDAPServer  我开始的时候参照他的例子 LDAPServer ldap://example.china 导致认证不过,怀疑这样写LDAPSearchScope subtree 一直生效不了

3,LDAPUsers 第二个参数是过滤器,fliter,具体格式可参照  http://www.proftpd.org/docs/contrib/mod_ldap.html#LDAPUsers

4,   如果登录用户均为/home/ftp 则为以下配置:

LDAPGenerateHomedir on
LDAPGenerateHomedirPrefix /home/ftp/
LDAPGenerateHomedirPrefixNoUsername on
LDAPUsers OU=12,DC=345,DC=CHINA (sAMAccountName=%u)

如果为每个用户创建自己的目录,需要增加CreateHome 为on,然后LDAPGenerateHomedirPrefixNoUsername  off 即可

详细的ldap配置可参考:http://www.proftpd.org/docs/contrib/mod_ldap.htm

用户权限配置

以上配置后了,还需要配置用户目录权限

下面是我为所有用户配置的权限,限制重命名和删除,可读可写,但是实际好像还是有点问题,后面再深究

/etc/proftpd/proftpd.conf 

<Directory ~/>
   <Limit RNFR DELE RMD SITE_CHMOD>
     DenyAll
   </Limit>
   AllowOverwrite on
   AllowRetrieveRestart on
   AllowStoreRestart on
</Directory>

#<LIMIT>容器内有以下权限:
# CWD:改变所在目录
# MKD/XMKD:新建目录
# RNFR/RNTO:重命名目录的(一起使用)
# DELE:删除文件
# RMD/XRMD:删除目录
# RETR:下载
# STOR:上传
# LOGIN:登陆
# READ:包括了RETR,SITE,SIZE,STAT
# WRITE:包括了APPE, DELE, MKD, RMD, RNTO, STOR, XMKD, XRMD
# DIRS:包括了DUP, CWD, LIST, MDTM, NLST, PWD, RNFR, XCUP, XCWD, XPWD
# ALL:包括了READ WRITE DIRS
#以上权限结合动作一起使用:
# AllowUser:允许某个用户
# DenyUser:禁止某个用户
# AllowGroup:允许某个用户组
# DenyGroup:禁止某个用户组
# AllowAll:允许所有用户
# DenyAll:禁止所有用户

配置完成后,重启服务

 sudo /etc/init.d/proftpd  restart

参照:https://blog.csdn.net/hanchaoqi/article/details/38733863

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值