CentOS7 mini安装FTP

用了一段时间的CentOS,发现没有交互的界面传起文件来特麻烦,每次都敲一堆指令,用rz指令还不能用覆盖,只能删除再安装,所以这里我用FTP来传输,操作也方便很多。转载大神的操作:

一、安装vsftpd
  1、安装vsftpd: yum install vsftpd -y
  2、启动vsftpd: systemctl start vsftpd
  3、设置开机启动:systemctl enable vsftpd

  4、创建ftp根目录: mkdir -p /ftpserver

二、设置配置文件:vi /etc/vsftpd/vsftpd.conf

注意:每条设定后面不能有空格或注释

vsftpd服务程序常用的参数以及作用:

参数作用
listen=[YES|NO]是否以独立运行的方式监听服务
listen_address=IP地址设置要监听的IP地址
listen_port=21设置FTP服务的监听端口
download_enable=[YES|NO]是否允许下载文件
userlist_enable=[YES|NO]
userlist_deny=[YES|NO]
设置用户列表为“允许”还是“禁止”操作
max_clients=0最大客户端连接数,0为不限制
max_per_ip=0同一IP地址的最大连接数,0为不限制
anonymous_enable=[YES|NO]是否允许匿名用户访问
anon_upload_enable=[YES|NO]是否允许匿名用户上传文件
anon_umask=022匿名用户上传文件的umask值
anon_root=/var/ftp匿名用户的FTP根目录
anon_mkdir_write_enable=[YES|NO]是否允许匿名用户创建目录
anon_other_write_enable=[YES|NO]是否开放匿名用户的其他写入权限(包括重命名、删除等操作权限)
anon_max_rate=0匿名用户的最大传输速率(字节/秒),0为不限制
local_enable=[YES|NO]是否允许本地用户登录FTP
local_umask=022本地用户上传文件的umask值
local_root=/var/ftp本地用户的FTP根目录
chroot_local_user=[YES|NO]是否将用户权限禁锢在FTP目录,以确保安全
local_max_rate=0本地用户最大传输速率(字节/秒),0为不限制

可以向匿名用户开放的权限参数以及作用:

参数作用
anonymous_enable=YES允许匿名访问模式
anon_umask=022匿名用户上传文件的umask值
anon_upload_enable=YES允许匿名用户上传文件
anon_mkdir_write_enable=YES允许匿名用户创建目录
anon_other_write_enable=YES允许匿名用户修改目录名称或删除目录

本地用户模式使用的权限参数以及作用:

参数作用
anonymous_enable=NO禁止匿名访问模式
local_enable=YES允许本地用户模式
write_enable=YES设置可写权限
local_umask=022本地用户模式创建文件的umask值
userlist_deny=YES启用“禁止用户名单”,名单文件为ftpusers和user_list
userlist_enable=YES开启用户作用名单文件功能

利用PAM文件进行认证时使用的参数以及作用:

参数作用
anonymous_enable=NO禁止匿名开放模式
local_enable=YES允许本地用户模式
guest_enable=YES开启虚拟用户模式
guest_username=virtual指定虚拟用户账户
pam_service_name=vsftpd.vu指定PAM文件
allow_writeable_chroot=YES允许对禁锢的FTP根目录执行写入操作,而且不拒绝用户的登录请求

具体需要配置内容:


       listen=NO                  
  listen_address=192.168.1.196           
  #禁止匿名访问
  anonymous_enable=NO
  anon_upload_enable=NO
  anon_mkdir_write_enable=NO
  anon_other_write_enable=NO

listen_address=192.168.1.196
# 权限验证需要的加密文件
pam_service_name=vsftpd.vu
# 开启虚拟用户功能 
guest_enable=YES
# 虚拟用户的宿主目录
guest_username=ftp
# 用户登录后操作目录和本地用户权限一样
virtual_use_local_privs=YES
# 虚拟用户主目录设置文件
user_config_dir=/etc/vsftpd/vconf
# 允许写入用户主目录,这条特别重要
allow_writeable_chroot=YES

 

最终修改结果:

# 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=NO
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=NO
#
# 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
#
# 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
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
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. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# 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
#
# 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
#
# 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
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
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. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# 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().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
chroot_local_user=YES
chroot_list_enable=NO
# (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. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then 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

###########################################
listen_address=192.168.1.196
# 权限验证需要的加密文件
pam_service_name=vsftpd.vu
# 开启虚拟用户功能 
guest_enable=YES
# 虚拟用户的宿主目录
guest_username=ftp
# 用户登录后操作目录和本地用户权限一样
virtual_use_local_privs=YES
# 虚拟用户主目录设置文件
user_config_dir=/etc/vsftpd/vconf
# 允许写入用户主目录,这条特别重要
allow_writeable_chroot=YES
###########################################
###########################################

 

三、添加用户,并创建用户目录

  1、vi /etc/vsftpd.chroot_list,添加两个用户如进去,分别为:

  user1

  user2

  2、 mkdir -p /ftpserver/user1 mkdir /ftpserver/user2    //创建目录

  3、chmod -R 755 /ftpserver/user1 /ftpserver/user2 // 修改目录权限

四、设置用户密码和数据库

  1、echo -e "user1\n123456\nuser2\n123456" >/etc/vsftpd/vusers.list   // 创建用户和密码

  2、cd /etc/vsftpd                              

  3、db_load -T -t hash -f vusers.list vusers.db

  4、chmod 600 vusers.*

五、指定认证方式,添加如下内容 vim /etc/pam.d/vsftpd.vu

注:db=/etc/vsftpd/vusers 中的vusers 是你生成的虚拟用户的db文件

查看系统版本号: getconf LONG_BIT

系统为32位:

#%pam-1.0
auth   required  pam_userdb.so  db=/etc/vsftpd/vusers
account  required  pam_userdb.so  db=/etc/vsftpd/vusers 

系统为64位:

#%pam-1.0

auth          required     /lib64/security/pam_userdb.so    db=/etc/vsftpd/vusers

account    required     /lib64/security/pam_userdb.so    db=/etc/vsftpd/vusers

六、创建文件并指定ftp用户目录

  1、mkdir -p /etc/vsftpd/vconf

  2、cd /etc/vsftpd/vconf

  3、touch user1 user2
  4、添加内容,vim user1

    local_root=/ftpserver/user1

  5、vim user2

    local_root=/ftpserver/user2

七、重启服务即可访问FTP:systemctl restart vsftpd  /  service vsftpd restart 

八、添加新用户test1

  1、创建新用户目录:mkdir -p /ftpserver/test1
  
  2、 添加用户名,vi /etc/vsftpd/chroot_list,添加内容: test1
   
  3、修改目录权限chmod –R 755 /ftpserver/test1

  4、添加用户及密码,vi /etc/vsftpd/vusers.list
    test1      //用户名
    a123456    //密码
  5、设置数据库
    cd /etc/vsftpd
    db_load -T -t hash -f vusers.list vusers.db
    chmod 600 vusers.*
  6、创建文件名文件,并指定用户目录
    touch /etc/vsftpd/vconf/test1
    vim /etc/vsftpd/vconf/test1
    local_root=/ftpserver/test1

  7、重启服务即可:systemctl  restart vsftpd  /  service vsftpd restart 

注意事项:

1、如让用户有写入权限,则需给用户目录添加其它用户的写入权限: chmod o+w /ftpserver/user1
2、如还访问不了,记得设置(打开:vi /etc/selinux/config):SELINUX=disable

 

网上查找N多资料,终于连接成功,但是还有以下问题,待检查

1)只能在cmd里连接FTP,无法在文件夹里使用

2)cmd里用了一小段时间,连接就自动断开了

参考资料:

http://www.cnblogs.com/opsprobe/p/9185139.html

https://www.cnblogs.com/jefflee168/p/6575014.html

未完待续。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值