FTP是File Transfer Protocol(文件传输协议,简称文传协议)的英文简称,用于在Internet上控制文件的双向传输。FTP的主要做用就是让用户链接一个远程计算机(这些计算机上运行着FTP服务器程序),并查看远程计算机中的文件,而后把文件从远程计算机复制到本地计算机,或把本地计算机的文件传送到远程计算机。小公司用的多,大企业不用FTP,由于不安全。mysql
[root@gary-tao ~]# yum install -y vsftpd [root@gary-tao ~]# useradd -s /sbin/nologin virftp //建立一个普通用户,为了以这个用户的身份来传文件,-s是用来指定shell,/sbin/nologin是使这个用户不能登陆,保证安全 [root@gary-tao ~]# vim /etc/vsftpd/vsftpd_login //内容以下,奇数行为用户名,偶数行为密码,多个用户就写多行 testuser1 aminglinux [root@gary-tao ~]# chmod 600 /etc/vsftpd/vsftpd_login //更改文件权限,提高安全级别 [root@gary-tao ~]# cat /etc/vsftpd/vsftpd_login testuser1 aminglinux [root@gary-tao ~]# db_load -T -t hash -f /etc/vsftpd/vsftpd_login /etc/vsftpd/vsftpd_login.db //vsfpd使用的密码文件不是明文的,须要生成对应的库文件 [root@gary-tao ~]# ls -l /etc/vsftpd/ 总用量 36 -rw------- 1 root root 125 8月 3 14:10 ftpusers -rw------- 1 root root 361 8月 3 14:10 user_list -rw------- 1 root root 5030 8月 3 14:10 vsftpd.conf -rwxr--r-- 1 root root 338 8月 3 14:10 vsftpd_conf_migrate.sh -rw------- 1 root root 21 1月 16 17:12 vsftpd_login -rw-r--r-- 1 root root 12288 1月 16 17:16 vsftpd_login.db [root@gary-tao ~]# mkdir /etc/vsftpd/vsftpd_user_conf //创建虚拟帐号相关的目录以及配置文件 [root@gary-tao ~]# cd /etc/vsftpd/vsftpd_user_conf/
[root@gary-tao vsftpd_user_conf]# vim testuser1 //定义虚拟用户的配置文件 增长以下配置内容: local_root=/home/virftp/testuser1 //定义test1的家目录 anonymous_enable=NO //用来限制是否容许匿名帐号登陆(no表示不容许) write_enable=YES //表示可写 local_umask=022 //umask值 anon_upload_enable=NO //表示是否容许匿名帐号上传文件 anon_mkdir_write_enable=NO //表示是否容许匿名帐号可写 idle_session_timeout=600 //上传完文件后超时多久断开链接 data_connection_timeout=120 //数据传输超时时间 max_clients=10 [root@gary-tao vsftpd_user_conf]# mkdir /home/virftp/testuser1 [root@gary-tao vsftpd_user_conf]# touch /home/virftp/testuser1/aming.txt [root@gary-tao vsftpd_user_conf]# chown -R virftp:virftp /home/virftp [root@gary-tao vsftpd_user_conf]# vim /etc/pam.d/vsftpd //定义密码文件 增长配置内容以下: auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login //Centos7为64系统,全部库文件路径为/lib64/security/pam_userdb.so(32位系统的库文件路径为/lib/security/pam_userdb.so)
配置以下图:linux
[root@gary-tao vsftpd_user_conf]# vim /etc/vsftpd/vsftpd.conf 修改以下内容: 将anonymous_enable=YES 改成 anonymous_enable=NO 将#anon_upload_enable=YES 改成 anon_upload_enable=NO 将#anon_mkdir_write_enable=YES 改成 anon_mkdir_write_enable=NO 增长以下内容: chroot_local_user=YES guest_enable=YES guest_username=virftp virtual_use_local_privs=YES user_config_dir=/etc/vsftpd/vsftpd_user_conf allow_writeable_chroot=YES [root@gary-tao vsftpd_user_conf]# systemctl start vsftpd //启动vsftpd服务 [root@gary-tao vsftpd_user_conf]# ps aux |grep vsftpd root 18027 0.0 0.0 53216 576 ? Ss 19:20 0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf root 18029 0.0 0.0 112680 976 pts/1 R+ 19:21 0:00 grep --color=auto vsftpd [root@gary-tao vsftpd_user_conf]# 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: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 18027/vsftpd 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 -
配置以下图:sql
[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
//默认的Centos yum源并不包含pure-ftpd,须要安装epel扩展源 [root@gary-tao ~]# yum install -y epel-release [root@gary-tao ~]# yum install -y pure-ftpd
说明:shell
在启动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 -
为了安全,pure-ftpd使用的帐号并不是linux的系统帐号,而是虚拟帐号。vim
[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