Linux ftp ldap认证,vsftpd+ldap认证

一、环境

系统     CentOS 6.4x64最小化安装

IP      192.168.3.19

二、安装ldap[root@test ~]# yum install openldap openldap-* -y

[root@test ~]# yum install nscd nss-pam-ldapd nss-* pcre pcre-* -y

配置ldap[root@test ~]# cd /etc/openldap/

[root@test openldap]# cp /usr/share/openldap-servers/slapd.conf.obsolete slapd.conf

[root@test openldap]# cp slapd.conf slapd.conf_`date +%Y%m%d`.bak

[root@test openldap]# ll

total 32

drwxr-xr-x. 2 root root 4096 Jul 14 09:48 certs

-rw-r--r--. 1 root root  282 Jul 14 09:40 ldap.conf

drwxr-xr-x  2 root root 4096 Jul 14 09:48 schema

-rw-r--r--  1 root root 4635 Jul 14 09:49 slapd.conf

-rw-r--r--  1 root root 4635 Jul 14 09:49 slapd.conf_20150714.bak

drwx------  3 ldap ldap 4096 Jul 14 09:48 slapd.d

设置ldap管理员密码[root@test openldap]# slappasswd -s weyee

{SSHA}+lnTFVa2PrStKgqt4SNFk4pl7Vo7QFUr

[root@test openldap]# slappasswd -s weyee|sed -e "s#{SSHA}#rootpw\t{SSHA}#g" >>/etc/openldap/slapd.conf

[root@test openldap]# tail -1 /etc/openldap/slapd.conf

rootpw{SSHA}d+rLMyEPKqcBroWW0vvazZ1+DRY2UmsP

修改dc配置[root@test openldap]# vim /etc/openldap/slapd.conf

#以下参数大概在114行

database        bdb                                    #使用bdb数据库

suffix          "dc=test,dc=org"                       #定义dc,指定搜索的域

rootdn          "cn=admin,dc=test,dc=org"              #定义管理员的dn,使用这个dn能登陆openldap

优化ldap配置参数[root@test openldap]# vim /etc/openldap/slapd.conf

loglevel 296                    #定义日志级别

cachesize 1000                  #换成条目数

checkpoint 2048 10              #表示内存中达到2048k或者10分钟,执行一次checkpoint,即写入数据文件的操作

配置相关权限[root@test openldap]# vim /etc/openldap/slapd.conf

#删除默认权限,将下面的内容都删除

database config

access to *

by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage

by * none

# enable server status monitoring (cn=monitor)

database monitor

access to *

by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read

by dn.exact="cn=Manager,dc=my-domain,dc=com" read

by * none

#添加新的权限(这是2.3的权限设置方式)

access to *

by self write

by anonymous auth

by * read

配置syslog记录ldap的服务日志[root@test openldap]# cp /etc/rsyslog.conf /etc/rsyslog.conf_`date +%Y%m%d`.bak

#往配置文件中增加如下内容

[root@test openldap]# tail -1 /etc/rsyslog.conf

local4.*                    /var/log/ldap.log

#重启rsyslog服务

[root@test openldap]# /etc/init.d/rsyslog restart

Shutting down system logger:                               [  OK  ]

Starting system logger:                                    [  OK  ]

配置ldap数据库路径#创建数据文件

[root@test openldap]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG

[root@test openldap]# chown ldap.ldap /var/lib/ldap/DB_CONFIG

[root@test openldap]# chmod 700 /var/lib/ldap/

[root@test openldap]# ll /var/lib/ldap/

total 4

-rw-r--r-- 1 ldap ldap 845 Jul 14 09:58 DB_CONFIG

[root@test openldap]# egrep -v "\#|^$" /var/lib/ldap/DB_CONFIG

set_cachesize 0 268435456 1

set_lg_regionmax 262144

set_lg_bsize 2097152

[root@test openldap]# slaptest -u            #检查配置文件是否正常

config file testing succeeded

启动ldap服务[root@test ~]# /etc/init.d/slapd start

Starting slapd:                                            [  OK  ]

[root@test ~]# ps aux |grep ldap

ldap      1700  0.0  1.6 490532 16592 ?        Ssl  10:00   0:00 /usr/sbin/slapd -h  ldap:/// ldapi:/// -u ldap

root      1706  0.0  0.0 103240   868 pts/0    S+   10:00   0:00 grep ldap

[root@test ~]# netstat -tunlp |grep slapd

tcp        0      0 0.0.0.0:389                 0.0.0.0:*                   LISTEN      1700/slapd

tcp        0      0 :::389                      :::*                        LISTEN      1700/slapd

#添加到开机自启动

[root@test ~]# chkconfig  slapd on

#查看日志文件

[root@test ~]# tail /var/log/ldap.log

Jul 14 10:00:11 test slapd[1699]: @(#) $OpenLDAP: slapd 2.4.39 (Oct 15 2014 09:51:43) $#012#011mockbuild@c6b8.bsys.dev.centos.org:/builddir/build/BUILD/openldap-2.4.39/openldap-2.4.39/build-servers/servers/slapd

查询一下ldap的内容[root@test ~]# ldapsearch -LLL -W -x -H ldap://test.org -D "cn=admin,dc=test,dc=org" -b "dc=test,dc=org" "(udi=*)"

Enter LDAP Password:

ldap_bind: Invalid credentials (49)        #这里报错

#解决如下,删除默认2.4的配置文件,重新生成2.3的配置文件

[root@test ~]# rm -rf /etc/openldap/slapd.d/*

[root@test ~]# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/

55a46df9 bdb_monitor_db_open: monitoring disabled; configure monitor database to enable

config file testing succeeded

[root@test ~]# ll /etc/openldap/slapd.d/

total 8

drwxr-x--- 3 root root 4096 Jul 14 10:03 cn=config

-rw------- 1 root root 1302 Jul 14 10:03 cn=config.ldif

#修改权限

[root@test ~]# chown -R ldap.ldap /etc/openldap/slapd.d/

#重启服务

[root@test ~]# /etc/init.d/slapd restart

Stopping slapd:                                            [  OK  ]

Starting slapd:                                            [  OK  ]

#再次查询ldap内容

[root@test ~]# ldapsearch -LLL -W -x -H ldap://test.org -D "cn=admin,dc=test,dc=org" -b "dc=test,dc=org" "(udi=*)"

Enter LDAP Password:                     #密码是上文中的weyee

No such object (32)                      #ldap中还没有任何数据

创建一个系统用户user1,设置密码user1[root@test ~]# useradd user1

[root@test ~]# passwd user1

Changing password for user user1.

New password:

BAD PASSWORD: it is too short

BAD PASSWORD: is too simple

Retype new password:

passwd: all authentication tokens updated successfully.

安装migrationtools[root@test ~]# yum install migrationtools -y

编辑migrationtool的配置文件/usr/share/migrationtools/migrate_common.ph[root@test ~]# vim /usr/share/migrationtools/migrate_common.ph

# Default DNS domain

$DEFAULT_MAIL_DOMAIN = "test.org";

# Default base

$DEFAULT_BASE = "dc=test,dc=org";

下面利用pl脚本将/etc/passwd 和/etc/shadow生成LDAP能读懂的文件格式,保存在/tmp/下[root@test ~]# /usr/share/migrationtools/migrate_base.pl >/tmp/base.ldif

[root@test ~]# /usr/share/migrationtools/migrate_passwd.pl /etc/passwd >/tmp/passwd.ldif

[root@test ~]# /usr/share/migrationtools/migrate_group.pl /etc/group >/tmp/group.ldif

下面就要把这三个文件导入到LDAP,这样LDAP的数据库里就有了我们想要的用户#导入base

[root@test ~]# ldapadd -x -D "cn=admin,dc=test,dc=org" -W -f /tmp/base.ldif

Enter LDAP Password:

adding new entry "dc=test,dc=org"

adding new entry "ou=Hosts,dc=test,dc=org"

adding new entry "ou=Rpc,dc=test,dc=org"

adding new entry "ou=Services,dc=test,dc=org"

adding new entry "nisMapName=netgroup.byuser,dc=test,dc=org"

adding new entry "ou=Mounts,dc=test,dc=org"

adding new entry "ou=Networks,dc=test,dc=org"

adding new entry "ou=People,dc=test,dc=org"

adding new entry "ou=Group,dc=test,dc=org"

adding new entry "ou=Netgroup,dc=test,dc=org"

adding new entry "ou=Protocols,dc=test,dc=org"

adding new entry "ou=Aliases,dc=test,dc=org"

adding new entry "nisMapName=netgroup.byhost,dc=test,dc=org"

#导入passwd

[root@test ~]# ldapadd -x -D "cn=admin,dc=test,dc=org" -W -f /tmp/passwd.ldif

Enter LDAP Password:

adding new entry "uid=root,ou=People,dc=test,dc=org"

adding new entry "uid=bin,ou=People,dc=test,dc=org"

adding new entry "uid=daemon,ou=People,dc=test,dc=org"

adding new entry "uid=adm,ou=People,dc=test,dc=org"

adding new entry "uid=lp,ou=People,dc=test,dc=org"

adding new entry "uid=sync,ou=People,dc=test,dc=org"

adding new entry "uid=shutdown,ou=People,dc=test,dc=org"

adding new entry "uid=halt,ou=People,dc=test,dc=org"

adding new entry "uid=mail,ou=People,dc=test,dc=org"

adding new entry "uid=uucp,ou=People,dc=test,dc=org"

adding new entry "uid=operator,ou=People,dc=test,dc=org"

adding new entry "uid=games,ou=People,dc=test,dc=org"

adding new entry "uid=gopher,ou=People,dc=test,dc=org"

adding new entry "uid=ftp,ou=People,dc=test,dc=org"

adding new entry "uid=nobody,ou=People,dc=test,dc=org"

adding new entry "uid=dbus,ou=People,dc=test,dc=org"

adding new entry "uid=vcsa,ou=People,dc=test,dc=org"

adding new entry "uid=abrt,ou=People,dc=test,dc=org"

adding new entry "uid=haldaemon,ou=People,dc=test,dc=org"

adding new entry "uid=ntp,ou=People,dc=test,dc=org"

adding new entry "uid=saslauth,ou=People,dc=test,dc=org"

adding new entry "uid=postfix,ou=People,dc=test,dc=org"

adding new entry "uid=sshd,ou=People,dc=test,dc=org"

adding new entry "uid=tcpdump,ou=People,dc=test,dc=org"

adding new entry "uid=ldap,ou=People,dc=test,dc=org"

adding new entry "uid=nscd,ou=People,dc=test,dc=org"

adding new entry "uid=nslcd,ou=People,dc=test,dc=org"

adding new entry "uid=user1,ou=People,dc=test,dc=org"

#导入group

[root@test ~]# ldapadd -x -D "cn=admin,dc=test,dc=org" -W -f /tmp/group.ldif

再次查询ldap的内容[root@test ~]# ldapsearch -LLL -w weyee -x -H ldap://test.org -D "cn=admin,dc=test,dc=org" -b "dc=test,dc=org" "(uid=user1)"

dn: uid=user1,ou=People,dc=test,dc=org

uid: user1

cn: user1

objectClass: account

objectClass: posixAccount

objectClass: top

objectClass: shadowAccount

userPassword:: e2NyeXB0fSQxJEovVFNOUFhVJHdmWXhyN3MzdTNVa0NVN0h0WHlHVDA=

shadowLastChange: 16630

shadowMin: 0

shadowMax: 99999

shadowWarning: 7

loginShell: /bin/bash

uidNumber: 500

gidNumber: 500

homeDirectory: /home/user1

安装配置ldap客户端phpladpadmin[root@test ~]# rpm -ivh http://mirrors.ukfast.co.uk/sites/dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

[root@test ~]# yum install phpldapadmin -y

配置Apache's phpLDAPadmin的配置文件[root@test ~]# vim /etc/httpd/conf.d/phpldapadmin.conf

Order Allow,Deny

Allow from all

Allow from 127.0.0.1

Allow from ::1

Allow from 192.168.3.0

禁用自动登录[root@test ~]# vim /etc/phpldapadmin/config.php

#(line 398)

//$servers->setValue('login','attr','uid');

启动httpd服务[root@test ~]# service httpd start

Starting httpd:                                            [  OK  ]

通过web界面访问ldap地址是http://192.168.3.19/ldapadmin/

8575d51e320e3e884c168b807ec15bfc.png

091acb5bbc51b1a85ddb99bec54787a4.png

三、安装配置vsftp[root@test ~]# yum install vsftpd -y

修改pam_ldap配置文件[root@test ~]# vim /etc/pam_ldap.conf

host 192.168.3.19

# The distinguished name of the search base.

base dc=test,dc=org

#uri ldap://192.168.3.19

binddn cn=admin,dc=test,dc=org

bindpw weyee

#修改文件/etc/pam.d/vsftpd.vu

[root@test ~]# vim /etc/pam.d/vsftpd.vu

authrequiredpam_ldap.so

account requiredpam_ldap.so

编辑vsftpd配置文件[root@test ~]# vim /etc/vsftpd/vsftpd.conf

nonymous_enable=NO              #不允许匿名用户访问

anon_upload_enable=YES

anon_mkdir_write_enable=YES     #开启这项和上一项才能上传文件和文件夹

chroot_local_user=YES

guest_enable=YES                      #设定启用虚拟用户功能

guest_username=ftp                    #指定虚拟用户的宿主用户

pam_service_name=vsftpd.vu            #设定PAM服务下Vsftpd的验证配置文件名。

local_root=/data

启动vsftpd服务[root@test ~]# /etc/init.d/vsftpd start

Starting vsftpd for vsftpd:                                [  OK  ]

[root@test ~]# yum install ftp -y

[root@test ~]# chown -R ftp.ftp /data/

测试,在ldap中创建用户ldapftp,设置密码ldapftp#查看ldapftp用户

[root@test ~]# ldapsearch -LLL -w weyee -x -H ldap://test.org -D "cn=admin,dc=test,dc=org" -b "dc=test,dc=org" "(uid=ldapftp)"

dn: uid=ldapftp,ou=People,dc=test,dc=org

objectClass: posixAccount

objectClass: top

objectClass: inetOrgPerson

gidNumber: 0

givenName: ldapftp

sn: ldapftp

uid: ldapftp

homeDirectory: /home/ldapftp

cn: ldapftp

uidNumber: 5355

userPassword:: e1NIQX1XZnNSS0U1dlVhR0xma0lINlFqU0F2VDJqU1U9

[root@test ~]# id ldapftp

id: ldapftp: No such user

#从上面的结果能看出ldapftp用户只有ldap数据库中才有

#测试访问ftp

[root@test ~]# ftp 127.0.0.1

Connected to 127.0.0.1 (127.0.0.1).

220 (vsFTPd 2.2.2)

Name (127.0.0.1:root): ldapftp            #输入用户ldapftp

331 Please specify the password.

Password:

230 Login successful.                    #这里显示登陆成功

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> ls

227 Entering Passive Mode (127,0,0,1,151,90).

150 Here comes the directory listing.

-rw-r--r--    1 0        0               0 Jul 14 03:05 1.txt

-rw-r--r--    1 0        0               0 Jul 14 03:05 2.txt

drwx------    2 14       50           4096 Jul 14 03:07 新文件夹

226 Directory send OK.

我们再次创建一个ldap用户test,密码test[root@test ~]# id test

id: test: No such user

[root@test ~]# ldapsearch -LLL -w weyee -x -H ldap://test.org -D "cn=admin,dc=test,dc=org" -b "dc=test,dc=org" "(uid=test)"

dn: uid=test,ou=People,dc=test,dc=org

objectClass: posixAccount

objectClass: top

objectClass: inetOrgPerson

gidNumber: 0

givenName: test

sn: test

uid: test

homeDirectory: /home/test

cn: test

uidNumber: 41881

userPassword:: e1NIQX1xVXFQNWN5eG02WWNUQWh6MDVIcGg1Z3Z1OU09

#上面结果表明test用户只存在于ldap中

#用test访问ftp

[root@test ~]# ftp 127.0.0.1

Connected to 127.0.0.1 (127.0.0.1).

220 (vsFTPd 2.2.2)

Name (127.0.0.1:root): test

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> ls

227 Entering Passive Mode (127,0,0,1,208,151).

150 Here comes the directory listing.

-rw-r--r--    1 0        0               0 Jul 14 03:05 1.txt

-rw-r--r--    1 0        0               0 Jul 14 03:05 2.txt

drwx------    2 14       50           4096 Jul 14 03:07 新文件夹

226 Directory send OK.

到这里vsftpd+ldap的配置已完成

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/264375.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

es6-变量的解构赋值

从数组和对象中提取值,对变量进行赋值,这被称为解构 let [foo, [[bar], baz]] [1, [[2], 3]]; foo // 1 bar // 2 baz // 3let [ , , third] ["foo", "bar", "baz"]; third // "baz"let [x, , y] [1, 2, 3];…

浏览器的渲染原理

看到这个标题大家一定会想到这篇神文《How Browsers Work》,这篇文章把浏览器的很多细节讲得很细,而且也被翻译成了中文。为什么我还想写一篇呢?因为两个原因, 1)这篇文章太长了,阅读成本太大,不…

AO 直接调用GeoProcessing 工具

Geoprocessing是ArcGIS的一个基础组成部分。无论你是一个新手抑或老资格的专家,geoprocessing都是你使用ArcGIS完成每天工作的一部分。它提供了数据分析、数据管理和数据转换等对于所用GIS用户都必须的工具,当然也包括ArcObjects开发者。GIS程序通常需要…

Linux环境变量PSI指什么,PSI 文件扩展名: 它是什么以及如何打开它?

了解 PSI 问题常见的 PSI 打开问题缺少 PrimalScript双击你的 PSI 文件会提示消息 “%%os%% 无法打开 PSI 文件”。 通常,%%os%% 中会出现这种情况,因为 PrimalScript 未安装在你的电脑上。 由于您的操作系统不知道如何处理此文件,因此无法通…

linux 修改文件时间

1、ls -l *.sh 2、touch -d "10/13/2013" *.sh 【我想把所以的.sh文件修改到三个月前(2013年10月13)的时间。】3、ls -l *.sh 参考文章 http://blog.itpub.net/29283412/viewspace-1070106/ 另外也可以单独修改时间或者月份,如下以…

datetime模块日期转换和列表sorted排序

import datetime dt 2019010103 # 日期 2019年1月1日3时 dts (datetime.datetime.strptime(dt, %Y%m%d%H) datetime.timedelta(days-1)).strftime(%Y%m%d%H) # 将dt向前或向后调整(day表示天,hours表示表示小时,负数往前正数往后&#xf…

差距

现在看明白了自己的距离,该从何处下手? 时间是怎么争取出来的?转载于:https://www.cnblogs.com/rosion/archive/2009/04/11/1433450.html

linux 命令tf,Linux文件管理命令

本篇涉及命令:cat,tac,more,less,head,tail,file,stat,touch,which,whatis,whereis,ls,mkdir,rmdir,tree,cp,mv,rm文本文件查看类命令cat 查看文件内容(concatenate)cat命令用于查看一个或多个文本文件内容,可以将两个或两个以上的文件连接起来并显示&am…

Python实现——二元线性回归(最小二乘法)

2019/3/30二元线性回归——矩阵公式法_又名:对于python科学库的糟心尝试_ 二元线性回归严格意义上其实不过是换汤不换药,我对公式进行推导,其实也就是跟以前一样的求偏导并使之为零,并且最终公式的严格推导我大概也只能说是将将理…

CSharp设计模式读书笔记(18):中介者模式(学习难度:★★★☆☆,使用频率:★★☆☆☆)...

中介者模式(Mediator Pattern):用一个中介对象(中介者)来封装一系列的对象交互,中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互,中介者模式又称为调停…

AT命令解释

一、 AT命令解释&#xff1a;1、常用操作1.1 AT命令解释&#xff1a;检测Module与串口是否连通&#xff0c;能否接收AT命令&#xff1b;命令格式&#xff1a;AT<CR>命令返回&#xff1a;OK (与串口通信正常)&#xff08;无返回&#xff0c;与串口通信未连通&#xff09;测…

linux四种集群是什么,lvs四种集群特点及使用场景

一、 前言当一组服务器在高速的局域网或广域网中相互连接&#xff0c;其前端部署了一个负责负载调度的调度器(Director)的服务器系统。调度器能将网络请求无缝调度到真实服务器上(Real server)&#xff0c;客户访问集群系统提供的网络服务就像访问一台高性能、高可用的服务器一…

c#数据库訪问返回值类型为SqlDataReader时使用using时注意的问题

版权声明&#xff1a;本文为博主原创文章&#xff0c;未经博主同意不得转载。https://blog.csdn.net/u010512579/article/details/24011761 在封装通用 SQLSERVER 数据可訪问方法时&#xff0c;假设返回值类型为 SqlDataReader ,那么在创建连接字符串的时候。我们不能写成例如以…

BroadcastReceiver应用详解(转)

转自&#xff1a; http://blog.csdn.net/liuhe688/article/details/6955668 問渠那得清如許&#xff1f;為有源頭活水來。南宋.朱熹《觀書有感》 据说程序员是最爱学习的群体&#xff0c;IT男都知道&#xff0c;这个行业日新月异&#xff0c;必须不断地学习新知识&#xff0c;不…

深入浅出JSON

深入浅出JSON JSON定义 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式&#xff0c;易于阅读和编写&#xff0c;同时也易于机器解析和生成。它基于ECMA262语言规范&#xff08;1999-12第三版&#xff09;中JavaScript编程语言的一个子集。 JSON采用与编程语言…

就linux学习的一点感受,学习linux的体会

学linux的驱动设计一&#xff1a;首先先装个虚拟机吧&#xff0c;我觉得这个比较好&#xff0c;有些人建议直接装在硬盘上(我想他们是觉得有点环境压力吧)&#xff0c;可我觉得对于没有linux基础的还是先装虚拟机比较好。二&#xff1a;记住一些常用的命令&#xff0c;这个是学…

自动绑定数据源

自动绑定数据源实现数据控件与原始数据的绑定是实现数据展示与编辑的基本前提。在常规的设计模式下实现数据绑定有两种方式&#xff1a;1&#xff09;第一种方式&#xff1a;在窗体上引用数据对象→逐个拖放控件→分别设置控件与字段的绑定关系。这无疑是个不厌其烦的重复过程&…

Java工具类——通过配置XML验证Map

Java工具类——通过配置XML验证Map 背景 在JavaWeb项目中&#xff0c;接收前端过来的参数时通常是使用我们的实体类进行接收的。但是呢&#xff0c;我们不能去决定已经搭建好的框架是怎么样的&#xff0c;在我接触的框架中有一种就是通过Map来接收前端过来的所有参数&#xff0…

c语言用指针两个字母交换,c语言指针基础之用指针交换两个数(代码实例)

用指针交换两个数&#xff1a;void swap(int *p,int *q) {int temp;temp *p;*p *q;*q temp;}int main(){int a 3, *p,c 5, *q;p &a; //把变量a的地址赋值给指针p&#xff0c;即p指向aq &c;swap(p,q);printf("a %d,c %d\n", a, c);return 0;}注意&am…

如何在 Windows Server 2003、Windows 2000 和 Windows XP 中备份恢复代理的加密文件系统 (EFS) 私钥...

本 文介绍了如何在运行 Microsoft Windows Server 2003、Microsoft Windows 2000 或 Microsoft Windows XP 的计算机上备份恢复代理加密文件系统 (EFS) 私钥。当位于本地计算机上的 EFS 私钥副本丢失时&#xff0c;请使用恢复代理的私钥恢复数据。本文包含有关如何使用证书导出…