一:安装ftp
1.首先先安装ftp,使用yum命令
[root@localhost /]# yum install vsftpd
2.修改/etc/vsftpd/vsftpd.conf
[root@localhost /]# vi /etc/vsftpd/vsftpd.conf
3.关闭匿名用户登录
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
4.限制用户只能访问跟路径(默认/home/test)
# 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
将chroot_list的两个注释解开,并且在/etc/vsftpd下创建chroot_root文件,在文件中添加你要限制的用户,一个用户一行,切记。
5.开启监听,曾在linux7中尝试,却始终无法启动,后使用linux6.4一次就成功了,不知道为什么。。。
# 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
auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
二:添加用户
1.添加用户,使用 -d用来指向主目录 最后加上用户名
[root@localhost vsftpd]# useradd -d /home/test test
[root@localhost vsftpd]# passwd test //修改密码,可能修改密码的时候会无法通过linux校验,root用户无视就好,连续输入两次
2.修改用户的权限
[root@localhost vsftpd]# usermod -s /sbin/nologin test //用户无法通过xshall登录(如果想使用该用户通过xftp管理的,可以不设置)注:笔者在修改为这个状态以后,无法上传文件,也无法登陆,求解答。
[root@localhost vsftpd]# usermod -d /usr/test test //修改用户主目录到user/test
[root@localhost vsftpd]# usermod -s /bin/bash test //还原状态
用户权限可以修改配置文件,不过还没有试过,以后补充
[root@localhost vsftpd]# vi /etc/shells
1.500,在linux中输入一条命令,原因未知,之后再看
500 OOPS: cannot change directory:/home/test
500 OOPS: priv_sock_get_cmd
命令如下:
[root@localhost vsftpd]# setsebool -P ftp_home_dir 1
530 Permission denied.
确认黑名单中是否有你的用户
530 Login incorrect.
我的原因是权限给了/sbin/nologin ,将其调回预设就好了