0基础自学linux运维-2.6-centos6 centos7快速安装vsFTP(快速版)

一、centos6.5 vsftp安装

#已经禁用了iptables

service iptables stop

chkconfig iptables off

如果开iptables可以添加如下规则

iptables -I INPUT -p tcp  --dport 22 -j ACCEPT

iptables -I INPUT -p tcp  --dport 21 -j ACCEPT

iptables -I INPUT -p tcp  --dport 5000:5100 -j ACCEPT

iptables -P INPUT DROP

iptables -I OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

iptables -P OUTPUT ACCEPT

iptables -nL

#禁止了selinux

#如果off不行就不执行“setenforce 0”,有条件的话执行完下面命令最好重启一下系统

setenforce off

sed -i '/^SELINUX=/s/enforcing/disabled/' /etc/selinux/config

grep '^SELINUX=' /etc/selinux/config

#------------------------------------------------------直接刷命令-------------------------------------

#1.安装vsftpd-2.2.2-14.el6.x86_64

yum -y install vsftpd

chkconfig vsftpd on

#2.基于虚拟用户的配置

cd /etc/vsftpd/

cp vsftpd.conf vsftpd.conf.orig

#写入配置文件含被动模式

cat>>vsftpd.conf<

#by hua

user_config_dir=/etc/vsftpd/vuser_conf

pasv_enable=YES

pasv_min_port=5000

pasv_max_port=5100

pasv_promiscuous=YES

#force_dot_files=yes

EOF

#3.进行认证,安装Berkeley DB工具

yum install db4 db4-utils -y

#创建用户密码文本,单行为用户名,双行为密码

cat>>vuser_passwd.txt<

t1

123456

EOF

#生成虚拟用户认证的db文件,如果添加用户则需要重新生成一下vuser_passwd.db然后重启vsftp

db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db

cp /etc/pam.d/vsftpd  /etc/pam.d/vsftpd.orig

echo '#%PAM-1.0' >/etc/pam.d/vsftpd

echo 'auth required pam_userdb.so db=/etc/vsftpd/vuser_passwd'>>/etc/pam.d/vsftpd

echo 'account required pam_userdb.so db=/etc/vsftpd/vuser_passwd' >>/etc/pam.d/vsftpd

cat /etc/pam.d/vsftpd

#创建虚拟用户配置文件

mkdir /etc/vsftpd/vuser_conf

cd /etc/vsftpd/vuser_conf/

#下面建立t1账号配置,配置名和用户名一样,有多少个用户名就有多少个配置

cat>>t1<

local_root=/disk1/tools

local_umask=022

write_enable=YES

guest_enable=yes

guest_username=daemon

anonymous_enable=no

anon_world_readable_only=no

anon_upload_enable=yes

anon_mkdir_write_enable=yes

anon_other_write_enable=yes

anon_umask=002

file_open_mode=0774

EOF

service vsftpd start

chkconfig vsftpd on

mkdir -p /disk1/tools

chown daemon.daemon /disk1/tools

#为了安全禁止匿名用户登陆,如果发现问题可以去掉

sed -i '/anonymous_enable/s/YES/NO/' /etc/vsftpd/vsftpd.conf

grep 'anonymous_enable' /etc/vsftpd/vsftpd.conf

service vsftpd restart

#------------------------------------------------------直接刷命令-------------------------------------

★★★★★★★★★★★★★★★★★★★★注意事项start★★★★★★★★★★★★★★★★★★★★★★★

每一次修改用户账号都必须生成一次密码vuser_passwd.db文件,否则不会生效!!还要重启vsftp!

#下面是操作命令!

db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db

service vsftpd restart

“guest_username=系统用户”中的,如上例子中guest_username=daemon

daemon是系统用户,一定存在的,一般是web软件的进程名字,比如我的是nginx的话,就用nginx,如果有php进程我也把php配置文件进程用户改为nginx,

这样的好处是web就可以对你上传的文件进行写读删除,因为有的缓存文件是php动态生成的,必须有写入权限!修改权限,删除权限!

比如:我查看nginx和php进程

[root@vm5 ~]# ps -ef|grep nginx|grep -v grep

nginx    1634  1632  0 May23 ?        00:00:05 php-fpm: pool www

root      1648    1  0 May23 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

nginx    1821  1632  0 May23 ?        00:00:05 php-fpm: pool www

nginx    13818  1632  0 Jun08 ?        00:00:04 php-fpm: pool www

nginx    13851  1632  0 Jun08 ?        00:00:04 php-fpm: pool www

nginx    20165  1648  0 Aug17 ?        00:11:06 nginx: worker process

nginx    20166  1648  0 Aug17 ?        00:11:18 nginx: worker process

nginx    20167  1648  0 Aug17 ?        00:11:05 nginx: worker process

nginx    20168  1648  0 Aug17 ?        00:11:23 nginx: worker process

nginx    23453  1632  0 Jun12 ?        00:00:04 php-fpm: pool www

nginx    29795  1632  0 Jul12 ?        00:00:02 php-fpm: pool www

nginx    29796  1632  0 Jul12 ?        00:00:02 php-fpm: pool www

从上面可以看到nginx和php的启动进程是nginx用户(这个用户查/etc/passwd是存在的)

[root@vm5 ~]# grep nginx /etc/passwd

nginx:x:498:499:nginx user:/var/cache/nginx:/sbin/nologin

这样guest_username配置就要写成“guest_username=nginx”,web的nginx还要能读,主要是网站是php写的,以php进程为主,一般情况都会有缓存目录

要对其文件或目录进行增加,删除,修改,所以才配置“guest_username=nginx”,这样ftp虚拟用户t1的权限就和nginx一样了!

如果改为其它用户如daemon,那第目录和文件用户和组都是daemon!你上传了网站文件如果含缓存目录的话,PHP因不能写入和删除,就会出问题!

★★★★★★★★★★★★★★★★注意事项END★★★★★★★★★★★★★★★★★★★★★★★★


#3.错误解决:

500 OOPS: cannot locate user entry:daemon

说明没有nginx用户,可以修改guest_username=daemon为其他用户。

###FTP客户端使用注意事项##############

如果用FileZilla Client连接vsftpd,

1.“常规”选项:“登陆类型”用"正常",然后输入用户名和密码

2.“传输设置”选项中:“传输模式”要用修改为“主动”不能用“默认”否则会报错,连接不上

3.“字符集”选项:建议强制用UTF-8,因为我们是centos服务器

如果是cuteftp,直接就可以连接

#########END############################


二、centos7安装vsftp

#1.禁用防火墙firewalld

#用兼容centos6方式关闭

yum install -y net-tools

service firewalld stop

#也可以用systemctl命令关闭

systemctl stop firewalld

systemctl disable firewalld

#2.关闭了selinux

#如果off不行就不执行“setenforce 0”,有条件的话执行完下面命令最好重启一下系统

setenforce off

sed -i '/^SELINUX=/s/enforcing/disabled/' /etc/selinux/config

grep '^SELINUX=' /etc/selinux/config

#3.其实centos7安装vsftp很简单,按centos6.5安装,然后在配置文件中添加多一项“allow_writeable_chroot=YES”

echo 'allow_writeable_chroot=YES'>>/etc/vsftpd/vsftpd.conf

service vsftpd restart

注:

centos7用的是vsftp 3版本,centos6 yum安装的是2.2版本,不能添加“allow_writeable_chroot=YES”否则报错

500 OOPS: unrecognised variable in config file: allow_writeable_chroot

如果在centos7不添加“allow_writeable_chroot=YES”,用FTP客户端连接也会报如下错误:

500 OOPS: vsftpd: refusing to run with writable root inside chroot()

从2.3.5之后,vsftpd增强了安全检查,如果用户被限定在了其主目录下,则该用户的主目录不能再具有写权限了!

如果检查发现还有写权限,就会报上面提示的错误。

★★★★★每一次修改用户账号都必须生成一次密码vuser_passwd.db文件,否则不会生效!!还要重启vsftp!

#下面是操作命令!

db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db

service vsftpd restart

你可能感兴趣的:(0基础自学linux运维-2.6-centos6 centos7快速安装vsFTP(快速版))