安全矩阵

 找回密码
 立即注册
搜索
查看: 2863|回复: 0

建议收藏 | Ubuntu16.04 ftp服务器安装+配置

[复制链接]

991

主题

1063

帖子

4315

积分

论坛元老

Rank: 8Rank: 8

积分
4315
发表于 2021-3-2 22:37:07 | 显示全部楼层 |阅读模式
原文链接:建议收藏 | Ubuntu16.04 ftp服务器安装+配置

ftp服务器安装与配置

1. ftp服务端的安装


如果之前配置过ftp服务器的还是之后配置的服务器,无法启动服务,那么基本是配置出现了错误,那么可先完全卸载后再进行安装。如果无法定位多半是镜像源的问题,请更换阿里源。
sudo apt-get update     
sudo apt-get install vsftpd   
vsftpd --version     //检测是否安装


2. ftp服务端的配置
vim /etc/vsftpd.conf    //编辑配置文件
修改vsftpd.conf文件如下:
  1. listen=NO //是否开启监听ipv4和ipv6数据
  2.     listen_ipv6=YES //是否开启监听ipv6数据
  3.      
  4.     # Allow anonymous FTP? (Disabled by default).
  5.     anonymous_enable=NO //是否允许匿名登陆,无需密码
  6.      
  7.     # Uncomment this to allow local users to log in.
  8.     local_enable=YES //是否允许本地用户登录
  9.      
  10.     # Uncomment this to enable any form of FTP write command.
  11.     write_enable=YES //是否允许登陆者上传文件
  12.      
  13.     # Default umask for local users is 077. You may wish to change this to 022,
  14.     # if your users expect that (022 is used by most other ftpd's)
  15.     local_umask=022         //设置本地用户默认要减免的权限
  16.      
  17.     # Activate directory messages - messages given to remote users when they
  18.     # go into a certain directory.
  19.     dirmessage_enable=YES //目录消息,能够给远程登陆的用户发送目录
  20.     #
  21.     # If enabled, vsftpd will display directory listings with the time
  22.     # in your local time zone. The default is to display GMT. The
  23.     # times returned by the MDTM FTP command are also affected by this
  24.     # option.
  25.     use_localtime=YES //服务器所展示的目录将随着本地时间而改变
  26.     #
  27.     # Activate logging of uploads/downloads.
  28.     xferlog_enable=YES //开启上传下载的日志记录
  29.     #
  30.     # Make sure PORT transfer connections originate from port 20 (ftp-data).
  31.     connect_from_port_20=YES //确认连接传输的端口号为20
  32.      
  33.     # You may override where the log file goes if you like. The default is shown
  34.     # below.
  35.     xferlog_file=/var/log/vsftpd.log //日志文件存放位置
  36.     #
  37.     # If you want, you can have your log file in standard ftpd xferlog format.
  38.     # Note that the default log file location is /var/log/xferlog in this case.
  39.     xferlog_std_format=YES //日志文件采用标准格式
  40.      
  41.      
  42.     # You may fully customise the login banner string:
  43.     ftpd_banner=Welcome to FTP service. //在使用shell时登陆那么会发送欢迎语
  44.      
  45.      
  46.     # You may specify an explicit list of local users to chroot() to their home
  47.     # directory. If chroot_local_user is YES, then this list becomes a list of
  48.     # users to NOT chroot().
  49.     # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
  50.     # the user does not have write access to the top level directory within the
  51.     # chroot)
  52.     chroot_local_user=YES //对本地用户是否实施限制
  53.     chroot_list_enable=YES //开启限制白名单
  54.     # (default follows)
  55.     chroot_list_file=/etc/vsftpd.chroot_list //白名单路径,若无这个文件需要自己创建
  56.      
  57.     # This option should be the name of a directory which is empty. Also, the
  58.     # directory should not be writable by the ftp user. This directory is used
  59.     # as a secure chroot() jail at times vsftpd does not require filesystem
  60.     # access.
  61.     secure_chroot_dir=/var/run/vsftpd/empty
  62.     #
  63.     # This string is the name of the PAM service vsftpd will use.
  64.     # pam_service_name=vsftpd
  65.     pam_service_name=ftp //此处ubuntu的系统需要改为ftp
  66.      
  67.     # This option specifies the location of the RSA certificate to use for SSL
  68.     # encrypted connections.
  69.     rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
  70.     rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
  71.     ssl_enable=NO
  72.      
  73.     #
  74.     # Uncomment this to indicate that vsftpd use a utf8 filesystem.
  75.     utf8_filesystem=YES //编码统一为utf8编码,可以识别中文,防止乱码
复制代码

3. vftpd配置完成


添加设置ftpuser用户和访问目录1. 创建ftp用户组和用户
  1. sudo groupadd ftpusers //创建ftpusers用户组
  2. sudo useradd -m ftpuser_lxr//创建一个用户并且自动创建家目录为/home/ftpuser_lxr
  3. (第二种方式:mkdir /home/ftpuser_lxr //先创建家目录sudo userad -d /home/ftpuser_lxr ftpuser_lxr //绑定这个家目录)
  4. usermod -G ftpusers ftpuser_lxr //将这个新用户加入到ftpusers用户组中
  5. sudo passwd ftpuser_lxr //更改密码
  6. mkdir /home/ftpuser_lxr/ftp //为用户添加一个具有一定权限的文件夹
  7. chmod 777 -R /home/ftpuser_lxr/ftp //新建一个pub目录用于存放文件,并且赋予全部权限
  8. usermod -s /sbin/nologin username //限制用户登录方式;限制用户username只能通过ftp登陆,而不能直接登陆服务器
复制代码

2.将该用户加入vsftpd.chroot_list白名单中
  1. mkdir /etc/vsftpd.chroot_list
  2.     vim vsftpd.chroot_list
复制代码
该文件内容如下:
  1. #白名单
  2.     ftpuser_lxr
复制代码

3.开启并重启vsftpd的服务

systemctl start vsftpd或者service vsftpd start
systemctl restart vsftpd或者service vsftpd restart



测试方法一:
  1. 打开浏览器,在地址栏输入:ftp://ip_addresss
复制代码

方法二:

  1. 在ubuntu中使用shell输入:ftp ip_address
复制代码


方法三:

  1. 在windows中在文件管理器地址栏输入:ftp://ip_addresss,该方式可以上传下载文件
复制代码

方法四:

  1. 在windows中使用cmd输入:ftp://ip_addresss //显示连接成功
复制代码






































回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-9-20 23:42 , Processed in 0.013203 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表