linux下ftp服务器的配置方法,以vsftpd配置为例加以介绍,vsftp提供3种远程的登录方式,vsftp的安装配置
linux下vsftpd服务器配置教程
这里简单介绍下vsftp的配置方法。
2)本地用户方式
3)虚拟用户方式
安装命令:
yum install vsftpd
2.2. 相关命令
[root@singledb ~]# service vsftpd start
Starting vsftpd for vsftpd: [ OK ] [root@singledb ~]# service vsftpd stop Shutting down vsftpd: [ OK ] [root@singledb ~]# service vsftpd restart Shutting down vsftpd: [FAILED] Starting vsftpd for vsftpd: [ OK ] [root@singledb ~]# /etc/init.d/vsftpd start Starting vsftpd for vsftpd: [FAILED] [root@singledb ~]# /etc/init.d/vsftpd stop Shutting down vsftpd: [ OK ] [root@singledb ~]# /etc/init.d/vsftpd restart Shutting down vsftpd: [FAILED] Starting vsftpd for vsftpd: [ OK ] [root@singledb ~]# /etc/init.d/vsftpd status vsftpd (pid 3931) is running... [root@singledb ~]#
2.2.2. 其他命令
--查看vsftpd 启动状态
[root@singledb ~]# chkconfig --list vsftpd vsftpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@singledb ~]# chkconfig vsftpd on [root@singledb ~]# chkconfig --list vsftpd vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
默认情况下从2到5设置为on了。2到5是多用户级别。 这个对应的是linux不同的运行级别。
[root@singledb ~]# chkconfig --level 0 vsftpd on
[root@singledb ~]# chkconfig --list vsftpd vsftpd 0:on 1:off 2:on 3:on 4:on 5:on 6:off
可以看到0已经设置为on了。
(1)查看防火墙
[root@singledb ~]# /etc/init.d/iptables status
Table: nat Chain PREROUTING (policy ACCEPT) num target prot opt source destination Chain POSTROUTING (policy ACCEPT) num target prot opt source destination 1 MASQUERADE all -- 192.168.122.0/24 !192.168.122.0/24 Chain OUTPUT (policy ACCEPT) num target prot opt source destination Table: filter Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:53 2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:53 3 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:67 4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:67 Chain FORWARD (policy ACCEPT) num target prot opt source destination 1 ACCEPT all -- 0.0.0.0/0 192.168.122.0/24 state RELATED,ESTABLISHED 2 ACCEPT all -- 192.168.122.0/24 0.0.0.0/0 3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 4 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable 5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable Chain OUTPUT (policy ACCEPT) num target prot opt source destination You have new mail in /var/spool/mail/root --添加开放21号端口: [root@singledb ~]# /sbin/iptables -I INPUT -p tcp --dport 21 -j ACCEPT [root@singledb ~]# /etc/init.d/iptables status Table: nat Chain PREROUTING (policy ACCEPT) num target prot opt source destination Chain POSTROUTING (policy ACCEPT) num target prot opt source destination 1 MASQUERADE all -- 192.168.122.0/24 !192.168.122.0/24 Chain OUTPUT (policy ACCEPT) num target prot opt source destination Table: filter Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:21 2 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:53 3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:53 4 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:67 5 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:67 Chain FORWARD (policy ACCEPT) num target prot opt source destination 1 ACCEPT all -- 0.0.0.0/0 192.168.122.0/24 state RELATED,ESTABLISHED 2 ACCEPT all -- 192.168.122.0/24 0.0.0.0/0 3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 4 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable 5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable Chain OUTPUT (policy ACCEPT) num target prot opt source destination --保存配置 [root@singledb ~]# /etc/rc.d/init.d/iptables save Saving firewall rules to /etc/sysconfig/iptables: [ OK ] --重启防火墙: [root@singledb ~]# service iptables {start|stop|restart}
2)查看关闭selinux
[root@singledb ~]# sestatus
SELinux status: disabled
在安装linux操作系统时关闭了selinux,如果没有关闭,可以修改如下文件来关闭:
[root@singledb ~]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - SELinux is fully disabled. SELINUX=disabled # SELINUXTYPE= type of policy in use. Possible values are: # targeted - Only targeted network daemons are protected. # strict - Full SELinux protection. SELINUXTYPE=targeted [root@singledb ~]#
保存退出,并重启系统reboot。
[root@singledb ~]# cd /etc/vsftpd/
[root@singledb vsftpd]# ls ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh [root@singledb vsftpd]#
vsftpd.conf: 主配置文件
[root@singledb vsftpd]# cat user_list
# vsftpd userlist # If userlist_deny=NO, only allow users in this file # If userlist_deny=YES (default), never allow users in this file, and # do not even prompt for a password. # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers # for users that are denied.
过滤掉#的注释后,查看vsftpd.conf配置文件:
[root@singledb ftp]# cat /etc/vsftpd/vsftpd.conf |grep -v '^#';
anonymous_enable=YES local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES listen=YES pam_service_name=vsftpd userlist_enable=yes tcp_wrappers=YES
可以在vsftpd.conf 文件设置如下参数:
#vi /etc/hosts.allow
vsftpd:192.168.5.128:DENY 设置该IP地址不可以访问ftp服务
FTP 访问时间限制:
#cp /usr/share/doc/vsftpd-1.1.3/vsftpd.xinetd /etc/xinetd.d/vsftpd
#vi /etc/xinetd.d/vsftpd/ #修改 disable = no access_time = hour:min-hour:min (添加配置访问的时间限制(注:与vsftpd.conf中listen=NO相对应)
例如:
[root@singledb ftp]# cat /etc/passwd | grep ftp
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
创建一个用户来访问FTP,并指定该用户的FTP目录:
[root@singledb u02]# useradd -d /u02/qsftp qs
[root@singledb u02]# passwd qs Changing password for user qs. New UNIX password: BAD PASSWORD: it is WAY too short Retype new UNIX password: passwd: all authentication tokens updated successfully.
这里指定的是/u02/qsftp 这个目录,要注意个目录的权限。
usermod -s /sbin/nologin username //用户只能ftp,不能telnet
usermod -s /sbin/bash username //用户恢复正常
禁止用户ssh登陆
useradd username -s /bin/false
更改用户主目录:
usermod -d /bbb username //把用户的主目录定为/bbb
然后,用qs这个用户就可以访问了。 |