使用pure-ftpd搭建ftp服务

1.安装pure-ftpd

//默认的Centos yum源并不包含pure-ftpd,需要安装epel扩展源

[root@gary-tao ~]# yum install -y epel-release
[root@gary-tao ~]# yum install -y pure-ftpd

2.配置pure-ftpd

说明:

在启动pure-ftpd之前,需要先修改配置文件/etc/pure-ftpd/pure-ftpd.conf。
其中需要把PureDB /etc/pure-ftpd/pureftpd.pdb前面的#删除,然后启动pure-ftpd,
启动之前需要关闭vsftpd,因为有端口冲突。
[root@gary-tao ~]# vim /etc/pure-ftpd/pure-ftpd.conf
//找到pureftpd.pdb这行,把行首的#删除

[root@gary-tao ~]# systemctl stop vsftpd
[root@gary-tao ~]# systemctl start pure-ftpd
[root@gary-tao ~]# ps aux |grep pure-ftpd
root      20478  0.0  0.1 202424  1204 ?        Ss   11:31   0:00 pure-ftpd (SERVER)
root      20480  0.0  0.0 112680   972 pts/1    R+   11:31   0:00 grep --color=auto pure-ftpd
[root@gary-tao ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      13969/rpc.mountd    
tcp        0      0 0.0.0.0:33684           0.0.0.0:*               LISTEN      13963/rpc.statd     
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      20478/pure-ftpd (SE 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      852/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1505/master         
tcp        0      0 0.0.0.0:34238           0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::3306                 :::*                    LISTEN      3373/mysqld         
tcp6       0      0 :::43663                :::*                    LISTEN      -                   
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::20048                :::*                    LISTEN      13969/rpc.mountd    
tcp6       0      0 :::21                   :::*                    LISTEN      20478/pure-ftpd (SE 
tcp6       0      0 :::22                   :::*                    LISTEN      852/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1505/master         
tcp6       0      0 :::44448                :::*                    LISTEN      13963/rpc.statd     
tcp6       0      0 :::2049                 :::*                    LISTEN      -             

3.建立账号

为了安全,pure-ftpd使用的账号并非linux的系统账号,而是虚拟账号。
[root@gary-tao ~]# mkdir /data/ftp
[root@gary-tao ~]# useradd -u 1010 pure-ftp
[root@gary-tao ~]# chown -R pure-ftp:pure-ftp /data/ftp
[root@gary-tao ~]# pure-pw useradd ftp_usera -u pure-ftp  -d /data/ftp
Password: 
Enter it again: 
//创建虚拟账户,-u是将虚拟用户ftp_usera与系统用户pure-ftp关联在一起,也就是说,使用ftp_usera账号登录ftp后,会以pure-ftp的身份来读取和下载文件,-d是指定ftp_usera账户的家目录,这样可以使用户ftp_usera只能访问其家目录/data/ftp/。

[root@gary-tao ~]# pure-pw mkdb
//创建用户信息数据库文件,这一步很关键。
[root@gary-tao ~]# pure-pw list  //列出当前账号
ftp_usera           /data/ftp/./                                                
[root@gary-tao ~]# pure-pw userdel ftp_usera  //删除账号

[root@gary-tao ~]# touch /data/ftp/123.txt
[root@gary-tao ~]# lftp ftp_usera@127.0.0.1  //测试连接
口令: 
lftp ftp_usera@127.0.0.1:~> ls      
drwxr-xr-x    2 1010       pure-ftp           21 Jan 17 11:40 .
drwxr-xr-x    2 1010       pure-ftp           21 Jan 17 11:40 ..
-rw-r--r--    1 0          0                   0 Jan 17 11:40 123.txt

测试ftp

[root@gary-tao vsftpd_user_conf]# yum install -y lftp
//安装lftp客户端软件

[root@gary-tao vsftpd_user_conf]# lftp testuser1@127.0.0.1
口令: 
lftp testuser1@127.0.0.1:~> ls      
ls: 登录失败: 530 Login incorrect.              
lftp testuser1@127.0.0.1:~> exit
[root@gary-tao vsftpd_user_conf]# lftp testuser1@127.0.0.1
口令: 
lftp testuser1@127.0.0.1:~> ls      
-rw-r--r--    1 1004     1004            0 Jan 16 11:03 aming.txt
lftp testuser1@127.0.0.1:/> ?
    !<shell-command>                     (commands)                           alias [<name> [<value>]]             attach [PID]
    bookmark [SUBCMD]                    cache [SUBCMD]                       cat [-b] <files>                     cd <rdir>
    chmod [OPTS] mode file...            close [-a]                           [re]cls [opts] [path/][pattern]
    debug [<level>|off] [-o <file>]      du [options] <dirs>                  exit [<code>|bg]
    get [OPTS] <rfile> [-o <lfile>]      glob [OPTS] <cmd> <args>             help [<cmd>]
    history -w file|-r file|-c|-l [cnt]  jobs [-v] [<job_no...>]              kill all|<job_no>                    lcd <ldir>
    lftp [OPTS] <site>                   ln [-s] <file1> <file2>              ls [<args>]
    mget [OPTS] <files>                  mirror [OPTS] [remote [local]]       mkdir [-p] <dirs>
    module name [args]                   more <files>                         mput [OPTS] <files>                  mrm <files>
    mv <file1> <file2>                   [re]nlist [<args>]                   open [OPTS] <site>
    pget [OPTS] <rfile> [-o <lfile>]     put [OPTS] <lfile> [-o <rfile>]      pwd [-p]
    queue [OPTS] [<cmd>]                 quote <cmd>                          repeat [OPTS] [delay] [command]
    rm [-r] [-f] <files>                 rmdir [-f] <dirs>                    scache [<session_no>]
    set [OPT] [<var> [<val>]]            site <site-cmd>                      source <file>
    torrent [-O <dir>] <file|URL>...     user <user|URL> [<pass>]             wait [<jobno>]                       zcat <files>
    zmore <files>
lftp testuser1@127.0.0.1:/> get aming.txt
lftp testuser1@127.0.0.1:/> quit
[root@gary-tao vsftpd_user_conf]# ls
aming.txt  testuser1
[root@gary-tao vsftpd_user_conf]# ls -lt |head
总用量 4
-rw-r--r-- 1 root root   0 1月  16 19:03 aming.txt
-rw-r--r-- 1 root root 204 1月  16 18:57 testuser1

 

  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值