pureftp、vsftp部署及优化
pure-ftp部署及优化pure-ftpd 官网 http://www.pureftpd.org/project/pure-ftpd
ftp服务器上:
# cd /usr/local/src/
#wget http://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.40.tar.gz
# tar zxvf pure-ftpd-1.0.40.tar.gz
# cd pure-ftpd-1.0.40
# ls
# ./configure \
--prefix=/usr/local/pureftpd \
--without-inetd \
--with-altlog \
--with-puredb \
--with-throttling \
--with-peruserlimits\
--with-tls
# make
# make install
# ls /usr/local/pureftpd/
binsbinshare
# mkdir -p /usr/local/pureftpd/etc/
# cd configuration-file
# cp pure-ftpd.conf /usr/local/pureftpd/etc/pure-ftpd.conf
# cp pure-config.pl /usr/local/pureftpd/sbin/pure-config.pl
# chmod 755 /usr/local/pureftpd/sbin/pure-config.pl
# vim /usr/local/pureftpd/etc/pure-ftpd.conf
ChrootEveryone yes
BrokenClientsCompatibilityno
MaxClientsNumber 50
Daemonize yes
MaxClientsPerIP 8
VerboseLog no
DisplayDotFiles yes
AnonymousOnly no
NoAnonymous no
SyslogFacility ftp
DontResolve yes
MaxIdleTime 15
PureDB /usr/local/pureftpd/etc/pureftpd.pdb
LimitRecursion 3136 8
AnonymousCanCreateDirs no
MaxLoad 4
AntiWarez yes
Umask 133:022
MinUID 100
AllowUserFXP no
AllowAnonymousFXP no
ProhibitDotFilesWrite no
ProhibitDotFilesRead no
AutoRename no
AnonymousCantUpload no
PIDFile /usr/local/pureftpd/var/run/pure-ftpd.pid
MaxDiskUsage 99
CustomerProof yes
# mkdir /tmp/ftp
# tail /etc/passwd
tom:x:500:500::/home/tom:/bin/bash
# chown -R tom:tom /tmp/ftp/
# /usr/local/pureftpd/bin/pure-pw useradd ftpuser1-utom -d /tmp/ftp
Password:
Enter it again:
//创建虚拟用户
# /usr/local/pureftpd/bin/pure-pw mkdb
//创建密码文件
# /usr/local/pureftpd/bin/pure-pw list
ftpuser1 /tmp/ftp/./
//列出用户
# /usr/local/pureftpd/sbin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf
//启动
# /etc/init.d/rpcbind stop
# /etc/init.d/nfs stop
# ps aux |grep pure
root 317280.00.0 9248 600 ? Ss 17:27 0:00 pure-ftpd (SERVER)
root 317300.00.0 4356 748 pts/0 S+ 17:28 0:00 grep pure
# netstat -lnp |grep ftp
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 31728/pure-ftpd (SE
tcp 0 0 :::21 :::* LISTEN 31728/pure-ftpd (SE
# lftp ftpuser1@192.168.137.21
Password:
lftp ftpuser1@192.168.137.21:~> ls
drwxr-xr-x 2 500 tom 4096 Jul 21 16:28 .
drwxr-xr-x 2 500 tom 4096 Jul 21 16:28 ..
lftp ftpuser1@192.168.137.21:~> mkdir 123
mkdir ok, `123' created
lftp ftpuser1@192.168.137.21:/> ls
drwxr-xr-x 3 500 tom 4096 Jul 21 16:36 .
drwxr-xr-x 3 500 tom 4096 Jul 21 16:36 ..
drwxr-xr-x 2 500 tom 4096 Jul 21 16:36 123
lftp ftpuser1@192.168.137.21:/> quit
# ls /tmp/ftp/
123
# tail /var/log/messages
# cd /tmp/ftp/
# touch 12.txt
# vim 12.txt
12123
另一台客户端登入:
#lftp ftpuser1@192.168.137.21
Password:
lftp ftpuser1@192.168.137.21:/> ls
drwxr-xr-x 3 500 tom 4096 Jul 21 16:38 .
drwxr-xr-x 3 500 tom 4096 Jul 21 16:38 ..
-rw-r--r-- 1 0 0 6 Jul 21 16:38 12.txt
drwxr-xr-x 2 500 tom 4096 Jul 21 16:36 123
lftp ftpuser1@192.168.137.21:/> ? //查看有哪些命令
lftp ftpuser1@192.168.137.21:/> get 12.txt
6 bytes transferred
lftp ftpuser1@192.168.137.21:/> quit
# cat 12.txt
12123
# vim 11.txt
555555555
#lftp ftpuser1@192.168.137.21
lftp ftpuser1@192.168.137.21:~> put 11.txt
10 bytes transferred
lftp ftpuser1@192.168.137.21:/> ls
drwxr-xr-x 3 500 tom 4096 Jul 21 16:48 .
drwxr-xr-x 3 500 tom 4096 Jul 21 16:48 ..
-rw-r--r-- 1 500 tom 10 Jul 20 19:28 11.txt
-rw-r--r-- 1 0 0 6 Jul 21 16:38 12.txt
drwxr-xr-x 2 500 tom 4096 Jul 21 16:36 123
//上传成功
服务端:
# ls
11.txt12312.txt
# cat 11.txt //查看上传的文件成功了
555555555
vsftp部署及优化
# yum install -y vsftp
# killall pure-ftpd
# /etc/init.d/vsftpd start
# lftp tom@192.168.137.21
Password:
lftp tom@192.168.137.21:~> ls
lftp tom@192.168.137.21:~>
//无文件
# ls /home/tom/ //因为他的家目录下无任何文件
You have new mail in /var/spool/mail/root
# touch /home/tom/112.txt
# mkdir /home/tom/aabb
# ls
112.txtaabb
客户端登入:
//查看已创建了文件
# lftp tom@192.168.137.21
lftp tom@192.168.137.21:~> ls
-rw-r--r-- 1 0 0 0 Jul 21 09:06 112.txt
drwxr-xr-x 2 0 0 4096 Jul 21 09:06 aabb
lftp tom@192.168.137.21:~> cd /etc/
cd ok, cwd=/etc
lftp tom@192.168.137.21:/etc>
lftp tom@192.168.137.21:/etc> ls
//进入etc目录下,此操作权限过大,存在安全隐患
服务端配置:
# vim /etc/vsftpd/vsftpd.conf
chroot_local_user=YES
# /etc/init.d/vsftpd restart
客户端登入:
# lftp tom@192.168.137.21
Password:
lftp tom@192.168.137.21:~> cd /etc/
cd: Access failed: 550 Failed to change directory. (/etc)
lftp tom@192.168.137.21:/> cd /tmp/
cd: Access failed: 550 Failed to change directory. (/tmp)
lftp tom@192.168.137.21:/> pwd
ftp://tom@192.168.137.21/
lftp tom@192.168.137.21:/> ls
-rw-r--r-- 1 0 0 0 Jul 21 09:06 112.txt
drwxr-xr-x 2 0 0 4096 Jul 21 09:06 aabb
//访问仅限在该目录下
建虚拟用户
# useradd virftp -s /sbin/nologin
# vim /etc/vsftpd/vsftpd_login //创建用户密码文件
test1
111222
test2
aaa111
# chmod 600 /etc/vsftpd/vsftpd_login
# db_load -T -t hash -f /etc/vsftpd/vsftpd_login /etc/vsftpd/vsftpd_login.db
创建虚拟账号
# mkdir /etc/vsftpd/vsftpd_user_conf
# cd !$
cd /etc/vsftpd/vsftpd_user_conf
# vim test1
local_root=/home/virftp/test1
anonymous_enable=NO
write_enable=YES
local_umask=022
anon_upload_enable=NO
anon_mkdir_write_enable=NO
idle_session_timeout=600
data_connection_timeout=120
max_clients=10
max_per_ip=5
local_max_rate=50000
# mkdir /home/virftp/test1 //创建该家目录
# chown -R virftp:virftp !$
chown -R virftp:virftp /home/virftp/test1
# vim /etc/pam.d/vsftpd
auth sufficient /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account sufficient /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
//最开头两行添加,如果是64位系统改为/lib64/security/pam_userdb.so、/lib64/security/pam_userdb.so
# cat /etc/pam.d/vsftpd //确保文件中写的目录存在
# ls /lib/security/pam_userdb.so
/lib/security/pam_userdb.so //存在
# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=NO //匿名用户不能登入
local_enable=YES //本地系统用户可登入
anon_upload_enable=NO //匿名不可上传
anon_mkdir_write_enable=NO //匿名不可创建
chroot_local_user=YES
guest_enable=YES //使虚拟用户可登入
guest_username=virftp // guest用户为virftp
virtual_use_local_privs=YES
user_config_dir=/etc/vsftpd/vsftpd_user_conf //指定虚拟用户所在配置文件
# /etc/init.d/vsftpd restart
# cat /etc/vsftpd/vsftpd_login
test1
111222
test2
aaa111
# lftp test1@127.0.0.1
Password:
lftp test1@127.0.0.1:~> ls
lftp test1@127.0.0.1:/> pwd
ftp://test1@127.0.0.1/
# cd /home/virftp/test1/
# ls
# touch 2.txt
# mkdir 123
# lftp test1@127.0.0.1
Password:
lftp test1@127.0.0.1:~> ls
drwxr-xr-x 2 0 0 4096 Jul 21 10:13 123
-rw-r--r-- 1 0 0 0 Jul 21 10:13 2.txt
//查看创建文件成功
页:
[1]