linux上搭建ftp

linux上搭建ftp

重要 解决如何搭建ftp

        解决用户指定访问其根目录

        解决访问ftp超时连接

        解决ftp主动连接、被动连接的问题

1、安装ftp

   安装ftp前,先把防火墙关闭

#service iptables stop   (挺重要)

安装好后再根据需要的端口 添加到 iptables

  • 直接用yum安装 vsftp
# .执行以下安装命令
    yum install -y vsftpd

# .设置开机启动服务
    chkconfig vsftpd on

# .启动服务
    service vsftpd start
  • 配置 ftp 配置文件

这里只是简单的介绍几个必须的配置,具体用到的配置自己去配

#默认的配置文件是/etc/vsftpd/vsftpd.conf

 # Example config file /etc/vsftpd/vsftpd.conf
 #
 # The default compiled in settings are fairly paranoid. This sample file
 # loosens things up a bit, to make the ftp daemon more usable.
 # Please see vsftpd.conf.5 for all compiled in defaults.
 #
 # READ THIS: This example file is NOT an exhaustive list of vsftpd options.
 # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
 # capabilities.
 #
 # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
 anonymous_enable=NO  #是否允许匿名登录
 #
 # Uncomment this to allow local users to log in.
 # When SELinux is enforcing check for SE bool ftp_home_dir
 local_enable=YES
 #
 # Uncomment this to enable any form of FTP write command.
 write_enable=YES
 #
 # Default umask for local users is 077. You may wish to change this to 022,
 # if your users expect that (022 is used by most other ftpd's)
 local_umask=022
 #
 # Uncomment this to allow the anonymous FTP user to upload files. This only
 # has an effect if the above global write enable is activated. Also, you will
 # obviously need to create a directory writable by the FTP user.
 # When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
 #anon_upload_enable=YES
 #
 # Uncomment this if you want the anonymous FTP user to be able to create
 # new directories.
 #anon_mkdir_write_enable=YES
 #
 # Activate directory messages - messages given to remote users when they
 # go into a certain directory.
 dirmessage_enable=YES
 #
 # Activate logging of uploads/downloads.
 xferlog_enable=YES
 #PASV_enable=NO
 #
 # Make sure PORT transfer connections originate from port 20 (ftp-data).
 #主动登录
 connect_from_port_20=YES   #是否允许主动登录、数据传输端口为20(防火墙必须开放端口20)     【解决访问ftp超时连接】
 pasv_enable=NO             #是否被动登录,关闭被动登录                                  【解决ftp主动连接、被动连接的问题
47 #被动登录
#开启被动则把上面的 注释,添加下面几个
              xferlog_std_format=YES                                                           listen=NO               local_root=/mnt/ftp #配置 用户的目录
  • 添加用户

增加用户user001,指向目录/mnt/ftp,禁止登录SSH权限。

#添加用户,并配置根目录为 /mnt/ftp 即是 用户访问目录
useradd -d /mnt/ftp  -s /sbin/nologin user001

#添加密码
passwd user001

# 并且修改 /mnt/ftp 目录的权限
chmod -R 755 /mnt/ftp

#改变文件拥有者和群组 (看文件的拥有着,不是user001就需要)
chown user00l:user001 /mnt/ftp
  • 编辑/etc/vsftpd/chroot_list目录,把用户名添加上去即可
vi /etc/vsftpd/chroot_list

#添加 user001即可
user001

到目前为至,已经完成了,重启服务就可以登录测试了

#service vsftpd restart
上一篇:springboot多数据源配合docker部署mysql主从实现读写分离


下一篇:C++混合编程之idlcpp教程Python篇(9)