一.  FTP 说明

linux 系统下常用的FTP 是vsftp, 即Very Security File Transfer Protocol. 还有一个是proftp(Profession ftp)。 我们这里也是简单的说明下vsftp的配置。

vsftp提供3种远程的登录方式:

(1)匿名登录方式

就是不需要用户名,密码。就能登录到服务器电脑里面

(2)本地用户方式

需要帐户名和密码才能登录。而且,这个帐户名和密码,都是在你linux系统里面,已经有的用户。

(3)虚拟用户方式

同样需要用户名和密码才能登录。但是和上面的区别就是,这个用户名和密码,在你linux系统中是没有的(没有该用户帐号)

二.  Vsftp的安装配置

2.1  安装

vsftp 的安装包,可以在安装里找到。 用yum 安装过程也很简单。 具体参考:

Linux 搭建 YUM 服务器

http://blog.csdn.net/tianlesoftware/archive/2011/01/03/6113902.aspx

安装命令:yum install vsftpd

2.2. 相关命令

2.2.1 启动与关闭

[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不同的运行级别。

我们也可以加level 选项来指定:

[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了。

我们可以使用man chkconfig 来查看帮助:

--level levels

Specifies the run levels an operation should pertain to. It is  given  as  a string of numbers from 0 to 7. For example, --level 35 specifies runlevels 3             and 5.

传统的init 定义了7个运行级(run level),每一个级别都代表系统应该补充运行的某些特定服务:

(1)0级是完全关闭系统的级别

(2)1级或者S级代表单用户模式

(3)2-5 级 是多用户级别

(4)6级 是 重新引导的级别

关于Linux 的运行级别,在我的Blog:

Linux 开机引导与关机过程(5.1 init 和运行级)

http://blog.csdn.net/tianlesoftware/archive/2010/10/24/5962460.aspx

(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

我这里在安装操作系统的时候就关闭了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

三.  FTP配置文件

FTP 安装好之后,在/etc/vsftpd/目录下会有如下文件:

[root@singledb ~]# cd /etc/vsftpd/

[root@singledb vsftpd]# ls

ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh

[root@singledb vsftpd]#

vsftpd.conf: 主配置文件

ftpusers: 指定哪些用户不能访问FTP服务器

user_list: 指定的用户是否可以访问ftp服务器由vsftpd.conf文件中的userlist_deny的取值来决定。

[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 文件设置如下参数:

(1)ftpd_banner=welcome to ftp service :设置连接服务器后的欢迎信息

(2)idle_session_timeout=60 :限制远程的客户机连接后,所建立的控制连接,在多长时间没有做任何的操作就会中断(秒)

(3)data_connection_timeout=120 :设置客户机在进行数据传输时,设置空闲的数据中断时间

(4)accept_timeout=60 设置在多长时间后自动建立连接

(5)connect_timeout=60 设置数据连接的最大激活时间,多长时间断开,为别人所使用;

(6)max_clients=200 指明服务器总的客户并发连接数为200

(7)max_per_ip=3 指明每个客户机的最大连接数为3

(8)local_max_rate=50000(50kbytes/sec)  本地用户最大传输速率限制

(9)anon_max_rate=30000匿名用户的最大传输速率限制

(10)pasv_min_port=端口

(11)pasv-max-prot=端口号 定义最大与最小端口,为0表示任意端口;为客户端连接指明端口;

(12)listen_address=IP地址 设置ftp服务来监听的地址,客户端可以用哪个地址来连接;

(13)listen_port=端口号 设置FTP工作的端口号,默认的为21

(14)chroot_local_user=YES 设置所有的本地用户可以chroot

(15)chroot_local_user=NO 设置指定用户能够chroot

(16)chroot_list_enable=YES

(17)chroot_list_file=/etc/vsftpd/chroot_list(只有/etc/vsftpd/chroot_list中的指定的用户才能执行 )

(18)local_root=path 无论哪个用户都能登录的用户,定义登录帐号的主目录, 若没有指定,则每一个用户则进入到个人用户主目录;

(19)chroot_local_user=yes/no 是否锁定本地系统帐号用户主目录(所有);锁定后,用户只能访问用户的主目录/home/user,不能利用cd命令向上转;只能向下;

(20)chroot_list_enable=yes/no 锁定指定文件中用户的主目录(部分),文件:/chroot_list_file=path 中指定;

(21)userlist_enable=YES/NO 是否加载用户列表文件;

(22)userlist_deny=YES 表示上面所加载的用户是否允许拒绝登录;

(23)userlist_file=/etc/vsftpd/user_list 列表文件

限制IP 访问FTP:

#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相对应)

例: access_time = 8:30-11:30 17:30-21:30 表示只有这两个时间段可以访问ftp

ftp的配置基本上只有这些了。

默认情况下,ftp根目录是/var/ftp。 如果要修改这个目录位置,可以更改/etc/passwd 文件:

[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 这个目录,要注意个目录的权限。

更改用户不能telnet,只能ftp:

usermod -s /sbin/nologin username   //用户只能ftp,不能telnet

usermod -s /sbin/bash username      //用户恢复正常

禁止用户ssh登陆

useradd username -s /bin/false

更改用户主目录:

usermod -d /bbb username            //把用户的主目录定为/bbb

然后用qs这个用户就可以访问了。

以上只是一些简单的设置。 在用户权限这块还有很多内容可以研究。 比如特定用户的特定权限。 安全性等。 以后在研究了。

Linux FTP 服务器配置简单说明的更多相关文章

  1. Linux命令详解-ftp服务器配置

    1.ftp服务器配置 1.ftp安装: rpm –qa | grep ftp 2.查看安装内容: rpm-ql |more 3.启动ftp服务: service vsftpd start 4.配置文件 ...

  2. Linux curl使用简单介绍

    在两台新搬迁的微信服务器上执行命令: curl -H "Content-Type: application/json" -d '{"partner_no":&q ...

  3. 详述Linux ftp命令的使用方法

    转自:http://os.51cto.com/art/201003/186325.htm ftp服务器在网上较为常见,Linux ftp命令的功能是用命令的方式来控制在本地机和远程机之间传送文件,这里 ...

  4. 引用 Windows Server 2003 FTP服务器配置详解

    引用 昆神之星 的 Windows Server 2003 FTP服务器配置详解 1.FTP文件传输协议,主要用于计算机之间文件传输,是互联网上仅次于www的第二大服务.本文主要演示如何在Window ...

  5. Linux FTP的安装与配置

    Linux FTP的安装与配置   ftp安装部分,操作步骤如下: 可以使用yum命令直接安装ftp # yum install vsftpd ftp服务的开启与关闭命令: 开启:# service  ...

  6. Linux FTP的安装与配置(转)

    Linux FTP的安装与配置   ftp安装部分,操作步骤如下: 可以使用yum命令直接安装ftp # yum install vsftpd ftp服务的开启与关闭命令: 开启:# service  ...

  7. Linux下一个简单的日志系统的设计及其C代码实现

    1.概述 在大型软件系统中,为了监测软件运行状况及排查软件故障,一般都会要求软件程序在运行的过程中产生日志文件.在日志文件中存放程序流程中的一些重要信息, 包括:变量名称及其值.消息结构定义.函数返回 ...

  8. linux FTP安全配置

    linux FTP安全配置 关闭防火墙,selinux安全机制   service iptables stop  setenforce 0 匿名用户 匿名用户只能访问ftp服务器上的/var/ftp/ ...

  9. [转帖] Linux 创建一个简单的私有CA、发证、吊销证书

    原创帖子地址:   https://blog.csdn.net/mr_rsq/article/details/71001810 Linux 创建一个简单的私有CA.发证.吊销证书 2017年04月30 ...

随机推荐

  1. java工程开发之图形化界面之(第五课)

    下面我们将: 一)更加完整的解释Graphics类 二)使用方法来更清晰的重新编写前面图形小应用程序之一 三)介绍一些其他的绘图的方法 四)介绍方法init,它是类似于paint但是用于不同用途的另一 ...

  2. do{...}while(0)的妙用(转)

    源:http://www.cnblogs.com/lizhenghn/p/3674430.html 在学习第一门编程语言时,就已经介绍了顺序分支.条件分支.循环分支.比如循环分支有for.while. ...

  3. ZOJ 3939The Lucky Week<模拟/暴力>

    题意:我们认为日期的天数为1,11,21,并且是周一的为Lucky Week;现在给出第一个lucky week的日期,求第N个的lucky week: //1:四百年一轮回,从闰年和平年的判定可以推 ...

  4. inline-block的升级float:浮动

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. 疯狂JAVA讲义---第十二章:Swing编程(五)进度条和滑动条

    http://blog.csdn.net/terryzero/article/details/3797782 疯狂JAVA讲义---第十二章:Swing编程(五)进度条和滑动条 标签: swing编程 ...

  6. HDU 2167 Pebbles(状压DP)

    题目链接:Pebbles Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  7. HDU 5176 The Experience of Love 带权并查集

    The Experience of Love Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  8. Delphi xe7并行编程快速入门(转)

    源:http://blog.csdn.net/henreash/article/details/41315183 现在多数设备.计算机都有多个CPU单元,即使是手机也是多核的.但要在开发中使用多核的优 ...

  9. javascript的 replace() 方法的使用讲解

    String.prototype.replace() The replace() method returns a new string with some or all matches of a p ...

  10. Android学习笔记之Intent(2)

    打开网页 package com.jiahemeikang.helloandroid; import java.io.File; import com.jiahemikang.service.Echo ...