RHEL搭建FTP服务器步骤和问题解析(1)


简单地说,支持FTP协议的服务器就是FTP服务器,而RHEL 4是一个系统,要在RHEL 4中搭建FTP是一个复杂的过程,下面就来详细的讲解一下RHEL搭建FTP上的过程。

1、RHEL搭建FTP中首先修改配置文件使主机获得永久Ip地址
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
IPADDR=172.16.16.111
NETMASK=255.255.0.0
GATEWAY=172.16.16.1
ONBOOT=yes
TYPE=Ethernet

重启配置文件使之生效
# /etc/init.d/network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Setting network parameters: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]

需要关掉iptables系统防火墙,使用命令:
# service iptables stop
把安全级别调低
# vi /etc/selinux/config
把其中的:SELINUXTYPE=targeted改为SELINUXTYPE=disabled
在系统中vsftpd并没被默认安装,需要使用rpm命令安装一下
它在RHEL4的第1张光盘中,包文件的名称是vsftpd-2.0.1-5.i386.rpm

首先需要挂载光盘
# mount /dev/cdrom /media/cdrom
# cd /media/cdrom/RedHat/RPMS
# ls -l vsftpd*
-rw-r--r-- 25 root root 122195 Jan 6 2005 vsftpd-2.0.1-5.i386.rpm
挂载上去后,把它安装上去
# rpm -ivh vsftpd-2.0.1-5.i386.rpm
warning: vsftpd-2.0.1-5.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing...                ########################################### [100%]

我们看一下vsftpd.conf的配置文件
# grep -v '#' /etc/vsftpd/vsftpd.conf(去除注释行后的配置文件)
anonymous_enable=YES  //anonymous_enable设置为yes时,ftp服务器允许匿名登录,即用户可使用用户名ftp或anonymous进行ftp登录,登录口令为用户E-mail地址。
local_enable=YES      //local_enable设置为yes时允许本地用户登录,本地用户指lunux系统中的用户账号。
write_enable=YES      //write_enable设置为yes时,ftp服务器开放对本地用户的写权限
local_umask=022      //local_umask设置项设置本地用户的文件生成掩码,配置文件中的设置为022。
dirmessage_enable=YES   //dirmessage_enable设置为yes时,当切换到ftp服务器中的某个目录时,将显示该目录下的".message"隐含文件的内容.    
xferlog_enable=YES     //xferlog_enable设置为yes时,ftp服务器将启用上传和下载日志。
connect_from_port_20=YES  //connect_from_port_20设置为yes时,ftp服务器将启用ftp数据端口的连接请求。
xferlog_std_format=YES    //xferlog_std_format设置为yes时,ftp服务器将使用标准的ftpd xferlog日志格式。
pam_service_name=vsftpd   //pam_service_name设置PAM认证服务的配置文件名称,该文件保存在"/etc/pam.d/"目录下。
userlist_enable=YES     //userlist_enable设置为yes时,ftp服务器将检查userlist_file设置文件中指定的用户是否可以访问vsftpd服务器;userlist_file配置项默认值是"/etc/vsftpd.usr_list"文件。
listen=YES         //listen设置为yes时,ftp服务器将处于独立启动模式。
tcp_wrappers=YES  //tcp_wrappers设置为yes时,ftp服务器将使用tcp_wrappes作为主机访问控制方式。tcp_wrappers可以实现linux系统中网络服务的基于主机地址的访问控制,在"/etc"目录中的hosts.allow和host.deny两个文件用于设置tcp_wrappers的访问控制,hosts.allow文件设置允许访问记录,host.deny文件设置拒绝访问记录。

启动vsftpd服务器
# service vsftpd start
Starting vsftpd for vsftpd: [ OK ]

关闭可以使用:
service vsftpd stop
Shutting down vsftpd: [ OK ]

查看服务器的运行状态使用:
# service vsftpd status
vsftpd is stopped

添加两个本地用户,使用本地用户登录ftp
# useradd aa
# passwd aa
# useradd bb
# passwd bb

并改变目录的属主和属组
# chown aa.aa /home/aa
# chown bb.bb /home/bb
# ls -l /home
total 24
drwx------ 4 aa   aa   4096 May 26 12:15 aa
drwx------ 4 bb   bb   4096 May 26 12:16 bb

设置宿主目录权限
# chmod 770 /home/aa
# chmod 770 /home/bb
# ls -l /home
total 24
drwxrwx--- 4 aa   aa   4096 May 26 12:15 aa
drwxrwx--- 4 bb   bb   4096 May 26 12:16 bb

这时可以登录ftp
1、使用匿名用户登录
# ftp 172.16.16.121
Connected to 172.16.16.121.
220 (vsFTPd2.0.1)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (172.16.16.121:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (172,16,16,121,208,47)
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 Oct 04 2004 pub
226 Directory send OK.

其中匿名用户登录使用ftp或anonymous作为ftp登录的用户名,在vsftpd的默认设置时输入任何字符串或直接回车都可以登录,匿名用户登录后将以ftp服务器系统中的"/var/ftp"目录作为匿名用户的ftp根目录。

2、使用本地用户登录
# ftp 172.16.16.121
Connected to 172.16.16.121.
220 (vsFTPd2.0.1)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (172.16.16.121:root): aa
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (172,16,16,121,223,86)
150 Here comes the directory listing.
-rw-r--r--    1 0        0              19 May 26 03:48 11.txt
226 Directory send OK.
使用put命令可以将ftp客户机中的文件上传到ftp服务器中。
ftp> put 22.txt
local: 22.txt remote: 22.txt
227 Entering Passive Mode (172,16,16,121,86,19)
150 Ok to send data.
226 File receive OK.
30 bytes sent in 0.00086 seconds (34 Kbytes/s)
使用get命令可以将ftp服务器中的文件下载到ftp客户机中。
ftp> get 22.txt
local: 22.txt remote: 22.txt
227 Entering Passive Mode (172,16,16,121,143,82)
150 Opening BINARY mode data connection for 22.txt (30 bytes).
226 File send OK.
30 bytes received in 0.0005 seconds (58 Kbytes/s)

不过使用本地ftp用户账号存在一定的安全性,首先它是系统账号,一旦ftp服务器出现安全漏洞会对整个ftp服务器所在的linux主机造成威胁;另外就是本地用户账号可以离开用户宿主目录,转换到系统中的其他目录中,这对系统的安全有着一定的威胁。可是设置ftp本地用户禁锢在宿主目录中,这样可以防止它切换到其他的目录中。
在vsftpd服务器的配置文件vsftpd.conf中添加配置项chroot_local_user设置为YES,vsftpd服务器将会把本地用户禁锢在用户宿主目录中。

chroot_local_user=YES,配置完后记得要重启服务,这样ftp本地用户就只可以访问自己的目录了。

配置ftp服务器的虚拟目录,在vsftpd服务器中支持匿名用户、本地用户和虚拟用户3类用户账号
在前面认识了两种,其中匿名用户是名为anonymous或ftp的ftp用户,匿名ftp用户登录后将ftp服务器中的"/var/ftp"作为ftp根目录。匿名用户通常用于提供公共文件的下载。

本地用户账号时ftp服务器中的系统用户账号,使用ftp本地用户账号登录ftp服务器后,登录目录为本地用户的宿主目录。本地ftp用户账号通常和web服务器一起提供虚拟主机服务,作为网页虚拟主机更新网页的途径。

虚拟用户账号时为了保证ftp服务器的安全性,由vsftpd服务器提供的非系统用户账号。虚拟用户ftp登录后将把指定的目录作为ftp根目录。虚拟用户与本地用户具有类似的功能。


相关内容

    暂无相关文章