阿里云上创建FTP服务器和设置两个不同访问权限的用户

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fhqlongteng/article/details/82997684

简介

FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为“文传协议”。用于Internet上的控制文件的双向传输。同时,它也是一个应用程序(Application)。基于不同的操作系统有不同的FTP应用程序,而所有这些应用程序都遵守同一种协议以传输文件。互联网上提供文件存储和访问服务的计算机,他们依照的是FTP协议提供服务!支持FTP协议的服务器就是FTP服务器!FTP协议提供存储和传输服务的一套协议。下载”(Download)和”上传”(Upload)。”下载”文件就是从远程主机拷贝文件至自己的计算机上;”上传”文件就是将文件从自己的计算机中拷贝至远程主机上。用Internet语言来说,用户可通过客户机程序向(从)远程主机上传(下载)文件。

工作原理

FTP采用客户端/服务端的工作模式(C/S结构),通过TCP协议建立客户端和服务器之间的连接,但与其他大多数应用协议不同,FTP协议在客户端和服务端之间建立了两条通信链路,分别是控制链路和数据链路,其中,控制链路负责FTP会话过程中FTP命令的发送和接收,数据链路则负责数据的传输。FTP会话包含了两个通道,控制通道和数据通道,FTP的工作有两种方式,一种是主动模式,一种是被动模式,以FTPServer为参照物,主动模式,服务器主动连接客户端传输,被动模式,等待客户端的的连接 。(无论是主动模式还是被动模式,首先的控制通道都是先建立起来的,只是在数据传输模式上的区别)。

FTP的安装与配置

安装前准备

vsftpd是linux下的一款小巧轻快,安全易用的FTP服务器软件,是一款在各个Linux发行版中最受推崇的FTP服务器软件。

1.安装vsftpd,直接yum 安装就可以了

 阿里云centos 6和centos 7系统中服务操作的命令有变化

查看系统版本的命令如下

2.启动服务

对于centos 7系统的命令如下

systemctl enable vsftpd.service //设置开机自启动

systemctl start vsftpd.service //启动ftp服务

对于centos 6系统的命令如下

chkconfig  vsftpd on //设置开机自启动

service  vsftpd start //启动ftp服务

netstat -antup | grep ftp //查看ftp服务端口

   默认设置FTP可以匿名登陆访问,所以直接输入IP地址就可以连接到FTP服务器了

3.相关配置文件:

 

图片22

/etc/vsftpd/vsftpd.conf //主配置文件,核心配置文件

/etc/vsftpd/ftpusers //黑名单,这个里面的用户不允许访问FTP服务器

/etc/vsftpd/user_list //白名单,允许访问FTP服务器的用户列表

简单介绍一下vsftpd.conf文件中的配置参数

用户登陆控制

参数 说明
anonymous_enable=YES 接受匿名用户
no_anon_password=YES 匿名用户login时不询问口令
anon_root=(none) 匿名用户主目录
local_enable=YES 接受本地用户
local_root=(none) 本地用户主目录

用户权限控制

参数 说明
write_enable=YES 可以上传(全局控制)
local_umask=022 本地用户上传文件的umask
file_open_mode=0666 上传文件的权限配合umask使用
anon_upload_enable=NO 匿名用户禁止上传
anon_mkdir_write_enable=NO 匿名用户禁止建目录
anon_other_write_enable=NO 匿名用户禁止修改删除
chown_username=lightwiter 匿名上传文件所属用户名

详细的配置信息可以阅读vsftpd.conf文件中的注释 

[root@iZ2zearztjpjmgwxwtn48sZ ~]# cat /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.
# YES:允许匿名访问,NO:禁止匿名访问
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
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.
#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
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

4. 设置2个FTP访问用户

       更改/var/ftp/pub目录的权限,为ftp用户添加写权限,并重新加载配置文件

chmod o+w /var/ftp/pub/ #更改/var/ftp/pub目录的权限
systemctl restart vsftpd.service #重启ftp服才能生效
    创建用户zsm和ftpadmin, 其中zsm用户只用于下载权限,ftpadmin用户可以上传下载删除权限。
创建zsm用户
useradd  zsm   //创建zsm用户
passwd   zsm   //给zsm用户设置密码

创建ftpadmin用户
useradd  ftpadmin  
passwd   ftpadmin

       查看已经用户是否创建成功。即查看/etc/passwd

      对于vsftpd.conf文件的配置对于不同版本的vsftpd不一样,下面介绍2.2版本和3.0版本的配置区别。

       A.配置FTP,适用于vsftpd-2.2.2-24.e16.x86_64版本,给这两个用户设置固定的访问路径为var/ftp/pub,关闭匿名访问等,修改/etc/vsftpd/vsftpd.conf文件,如下图

      你的服务器下面/etc/vsftpd/可能没有chroot_list文件,没有的话直接创建一个文件,保持为空就可以了。

     B.配置FTP,适用于vsftpd-3.0.2-22.e17.x86_64版本(目前安装的最新版本),给这两个用户设置固定的访问路径为var/ftp/pub,关闭匿名访问等,修改/etc/vsftpd/vsftpd.conf文件,如下图

     chroot_local_user=YES时,只有/etc/vsftpd.chroot_list文件中指定的用户可以返回上一层,chroot_local_user=NO时,/etc/vsftpd.chroot_list文件中指定的用户禁止返回上一层。

     allow_writeeable_chroot=YES这一项没有的话或是chroot_list没有允许访问的ftp用户名,ftp用户无法登陆服务器,返回“响应:    500 OOPS: vsftpd: refusing to run with writable root inside chroot()”这个错误。

     你的服务器下面/etc/vsftpd/可能没有chroot_list文件,没有的话直接创建一个文件,注意里面要写入登陆ftp用户的用户行,每行一个用户名

    user_config_dir=/var/ftp 用于设置用户通过ftp能访问到的路径,后面要在这个目录下创建以两个用户名为文件名的文件,并在里面写入访问的路径。

      分别对ftpadmin和zsm文件写入ftp访问的路径

      到这里就完成了这两个FTP用户的配置,使用这两个用户都可以访问到/var/ftp/pub这个目录了,使用ftpadmin用户登陆,并且创建一个HDRC-VC0的文件夹。

 5、配置这两个FTP用户的权限

       这里使用的方法比较简单容易实现,是一个非常规方法,利用两个用户对一个目录具有不同文件操作权限来实现,即先用ftpadmin这个帐号登陆ftp服务器,创建一个目录后,这个目录的操作权限属于ftpadmin 这个用户,那么zsm这个用户就不能操作这个目录了。如下图,HDRC-VC0这个目录属于ftpadmin用户,其他的用户只有只读权限的。

      总结:到这里,我们实现了在阿里云服务器上创建FTP服务器,设置两个用户,一个具有上传下载删除权限,另外一个用户只具有只读下载权限。小伙伴们看懂了么?不懂没有关系,实现动手操作一遍就明白了。

猜你喜欢

转载自blog.csdn.net/fhqlongteng/article/details/82997684