ftp服务器搭建

  • FTP是文件传输协议,正是由于这种协议使得主机间可以共享文件。 FTP 使用TCP生成一个虚拟连接用于控制信息,然后再生成一个单独的 TCP 连接用于数据传输

vsftpd是一款在Linux发行版中最主流的FTP服务器程序;特点是小巧轻快,安全易用;能让其自身特点得发发挥和掌握。

目前在开源操作系统中常用的FTP服务器程序主要有vsftpd、ProFTPD、PureFTPd和wuftpd等,这么多FTP服务器程序,关键在于自己熟练哪一个就使用哪一个。今天我们来研究一下VSFTPD简单安装及使用。

安装命令: yum  install vsftpd*  -y

修改配置文件如下:

anonymous_enable=NO    //禁止匿名用户访问

local_enable=YES  //允许本地用户登录FTP

write_enable=YES   //允许用户在FTP目录有写入的权限

local_umask=022   //设置本地用户的文件生成掩码为022,默认是077

dirmessage_enable=YES //激活目录信息,当远程用户更改目录时,将出现提示信息

xferlog_enable=YES   //启用上传和下载日志功能

connect_from_port_20=YES  //启用FTP数据端口的连接请求

xferlog_std_format=YES  //是否使用标准的ftpd xferlog日志文件格式

listen=YES  //使vsftpd处于独立启动监听端口模式

pam_service_name=vsftpd //设置PAM认证服务配置文件名称,文件存放在/etc/pam.d/目录

userlist_enable=YES   //用户列表中的用户是否允许登录FTP服务器,默认是不允许

tcp_wrappers=YES    //使用tcp_wrqppers作为主机访问控制方式

 

1) 第一种方法就是使用系统用户登录FTP,但是也是比较危险的,先测试系统用户登录FTP,在Linux系统上创建useradd  test 用户,并为其设置名,然后在xp客户端打开我的电脑资源里面访问 ftp://10.1.21.50,输入用户名和密码即可访问,进行创建和删除操作。

2) 第二种方法比较安全,配置相对复杂一点,就是使用vsftpd虚拟用户登录FTP服务器进行常见的操作。

  • 首先安装FTP 虚拟用户需要用到的软件及认证模块
yum  install  pam*  db4*  --skip-broken  –y
  • 创建并生成vsftpd数据库文件vi /etc/vsftpd/ftpusers.txt,内容如下:

第一行为FTP虚拟用户,登录用户名,第二行为密码,第三行为用户名,依次类推。

test1
123
test2
123
test3
123
  • 生成数据库文件命令
db_load -T -t hash -f /etc/vsftpd/ftpusers.txt /etc/vsftpd/vsftpd_login.db
chmod 700 /etc/vsftpd/vsftpd_login.db
  • 配置PAM验证文件

在配置文件vi /etc/pam.d/vsftpd 行首加入如下两行认证语句:(如果是32位,lib64需改成lib,如果RedHat,加入的语句不一样,需注意)

需特别注意行首添加

auth    sufficient      /lib64/security/pam_userdb.so     db=/etc/vsftpd/vsftpd_login
account sufficient      /lib64/security/pam_userdb.so      db=/etc/vsftpd/vsftpd_login
  • 创建vsftpd映射本地用户

所有的FTP虚拟用户需要使用一个系统用户,这个系统用户不需要密码,也不需要登录。主要用来做虚拟用户映射使用。


useradd   –d   /data/ftpuser -s  /sbin/nologin  ftpuser
  • 主配置文件如下:
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES
ascii_upload_enable=YES
ascii_download_enable=YES
listen=YES
guest_enable=YES
guest_username=mushi
pam_service_name=vsftpd
user_config_dir=/etc/vsftpd/vsftpd_user_conf
virtual_use_local_privs=YES
  • 重启服务
systemctl restart vsftpd

这时候所有的虚拟用户共同使用/data/ftpuser目录上传下载,如果想使用自己独立的目录,可以在/etc/vsftpd/vsftpd_user_conf目录创建各自的配置文件,如给test1创建独立的配置文件,编辑文件

vi /etc/vsftpd/vsftpd_user_conf/test1

write_enable=YES
anon_world_readable_only=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
cmds_allowed=FEAT,REST,CWD,LIST,MDTM,MKD,NLST,PASS,PASV,PORT,PWD,QUIT,RMD,RETR,SIZE,TYPE,USER,ACCT,APPE,CDUP,HELP,MODE,NOOP,REIN,STAT,STOU,STRU,SYST,STOR
  • cmds_allowed参数
CWD - change working directory 更改目录
LIST - list remote files 列目录
MKD - make a remote directory 新建文件
NLST - name list of remote directory
PWD - print working directory 显示当前工作目录
RETR - retrieve a remote file 下载文件
STOR - store a file on the remote host 上传文件
DELE - delete a remote file 删除文件
RMD - remove a remote directory 删除目录
RNFR - rename from 重命名
RNTO - rename to 重命名
以上是常用的一些参数,大家对照学习一下!下面是列也的全部参数,供大家参考!
ABOR - abort a file transfer 取消文件传输
CWD - change working directory 更改目录
DELE - delete a remote file 删除文件
LIST - list remote files 列目录
MDTM - return the modification time of a file 返回文件的更新时间
MKD - make a remote directory 新建文件夹
NLST - name list of remote directory
PASS - send password
PASV - enter passive mode
PORT - open a data port 打开一个传输端口
PWD - print working directory 显示当前工作目录
QUIT - terminate the connection 退出
RETR - retrieve a remote file 下载文件
RMD - remove a remote directory
RNFR - rename from
RNTO - rename to
SITE - site-specific commands
SIZE - return the size of a file 返回文件大小
STOR - store a file on the remote host 上传文件
TYPE - set transfer type
USER - send username
less common commands:
ACCT* - send account information
APPE - append to a remote file
CDUP - CWD to the parent of the current directory
HELP - return help on using the server
MODE - set transfer mode
NOOP - do nothing
REIN* - reinitialize the connection
STAT - return server status
STOU - store a file uniquely
STRU - set file transfer structure
SYST - return system type

测试结果:

用不同用户登录上传文件到不同目录中,并且只有上传和下载权限,done.

 

posted @ 2021-01-06 18:18  李家琦  阅读(207)  评论(0编辑  收藏  举报