搭建一个linux ftp服务器.docx

上传人:b****3 文档编号:12625370 上传时间:2023-04-21 格式:DOCX 页数:11 大小:18.78KB
下载 相关 举报
搭建一个linux ftp服务器.docx_第1页
第1页 / 共11页
搭建一个linux ftp服务器.docx_第2页
第2页 / 共11页
搭建一个linux ftp服务器.docx_第3页
第3页 / 共11页
搭建一个linux ftp服务器.docx_第4页
第4页 / 共11页
搭建一个linux ftp服务器.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

搭建一个linux ftp服务器.docx

《搭建一个linux ftp服务器.docx》由会员分享,可在线阅读,更多相关《搭建一个linux ftp服务器.docx(11页珍藏版)》请在冰豆网上搜索。

搭建一个linux ftp服务器.docx

搭建一个linuxftp服务器

搭建一个linuxftp服务器

 

RHEL4中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/networkrestart

  Shuttingdowninterfaceeth0:

 [ OK ]

  Shuttingdownloopbackinterface:

 [ OK ]

  Settingnetworkparameters:

 [ OK ]

  Bringinguploopbackinterface:

 [ OK ]

  Bringingupinterfaceeth0:

 [ OK ]

  需要关掉iptables系统防火墙,使用命令:

  #serviceiptablesstop

  把安全级别调低

  #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-lvsftpd*

  -rw-r--r-- 25rootroot122195Jan 6 2005vsftpd-2.0.1-5.i386.rpm

  挂载上去后,把它安装上去

  #rpm-ivhvsftpd-2.0.1-5.i386.rpm

  warning:

vsftpd-2.0.1-5.i386.rpm:

V3DSAsignature:

NOKEY,keyIDdb42a60e

  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服务器将使用标准的ftpdxferlog日志格式。

  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服务器

  #servicevsftpdstart

  Startingvsftpdforvsftpd:

[ OK ]

  关闭可以使用:

  servicevsftpdstop

  Shuttingdownvsftpd:

[ OK ]

  查看服务器的运行状态使用:

  #servicevsftpdstatus

  vsftpdisstopped

  添加两个本地用户,使用本地用户登录ftp

  #useraddaa

  #passwdaa

  #useraddbb

  #passwdbb

  并改变目录的属主和属组

  #chownaa.aa/home/aa

  #chownbb.bb/home/bb

  #ls-l/home

  total24

  drwx------ 4aa  aa  4096May2612:

15aa

  drwx------ 4bb  bb  4096May2612:

16bb

  设置宿主目录权限

  #chmod770/home/aa

  #chmod770/home/bb

  #ls-l/home

  total24

  drwxrwx--- 4aa  aa  4096May2612:

15aa

  drwxrwx--- 4bb  bb  4096May2612:

16bb

  这时可以登录ftp

  1、使用匿名用户登录

  #ftp172.16.16.121

  Connectedto172.16.16.121.

  220(vsFTPd2.0.1)

  530PleaseloginwithUSERandPASS.

  530PleaseloginwithUSERandPASS.

  KERBEROS_V4rejectedasanauthenticationtype

  Name(172.16.16.121:

root):

anonymous

  331Pleasespecifythepassword.

  Password:

  230Loginsuccessful.

  RemotesystemtypeisUNIX.

  Usingbinarymodetotransferfiles.

  ftp>ls

  227EnteringPassiveMode(172,16,16,121,208,47)

  150Herecomesthedirectorylisting.

  drwxr-xr-x   20       0           4096Oct04 2004pub

  226DirectorysendOK.

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

  2、使用本地用户登录

  #ftp172.16.16.121

  Connectedto172.16.16.121.

  220(vsFTPd2.0.1)

  530PleaseloginwithUSERandPASS.

  530PleaseloginwithUSERandPASS.

  KERBEROS_V4rejectedasanauthenticationtype

  Name(172.16.16.121:

root):

aa

  331Pleasespecifythepassword.

  Password:

  230Loginsuccessful.

  RemotesystemtypeisUNIX.

  Usingbinarymodetotransferfiles.

  ftp>ls

  227EnteringPassiveMode(172,16,16,121,223,86)

  150Herecomesthedirectorylisting.

  -rw-r--r--   10       0             19May2603:

4811.txt

  226DirectorysendOK.

  使用put命令可以将ftp客户机中的文件上传到ftp服务器中。

  ftp>put22.txt

  local:

22.txtremote:

22.txt

  227EnteringPassiveMode(172,16,16,121,86,19)

  150Oktosenddata.

  226FilereceiveOK.

  30bytessentin0.00086seconds(34Kbytes/s)

  使用get命令可以将ftp服务器中的文件下载到ftp客户机中。

  ftp>get22.txt

  local:

22.txtremote:

22.txt

  227EnteringPassiveMode(172,16,16,121,143,82)

  150OpeningBINARYmodedataconnectionfor22.txt(30bytes).

  226FilesendOK.

  30bytesreceivedin0.0005seconds(58Kbytes/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根目录。

虚拟用户与本地用户具有类似的功能。

  虚拟用户账号的设置过程

  1、建立虚拟用户口令库文件.

  建立虚拟用户的口令库,文件中奇数行设置虚拟用户的用户名,偶数行设置用户的口令.

  使用文本编辑器建立名为logins.txt的用户口令库文件

  #vilogins.txt

  ee

  123

  rr

  456

  2、生成vsftpd的认证文件.

  首先我们需要安装一下db4-utils-4.2.52-7.1.i386.rpm,在第3张光盘中.

  #cd/media/cdrom/RedHat/RPMS/

  #rpm-ivhdb4-utils-4.2.52-7.1.i386.rpm

  warning:

db4-utils-4.2.52-7.1.i386.rpm:

V3DSAsignature:

NOKEY,keyIDdb42a60e

  Preparing...               ###########################################[100%]

  packagedb4-utils-4.2.52-7.1isalreadyinstalled

  然后使用db_load命令生成认证文件,"-f"命令选项设置的值时虚拟用户的口令库文件,即:

logins.txt.命令的参数设置为需要生成的认证文件名vsftpd_login.db,该文件放置在目录"/etc/vsftpd"中.

  #db_load-T-thash-flogins.txt/etc/vsftpd/vsftpd_login.db

  设置vsftpd_login.db文件的权限只对root用户可读可写.即600.

  #chmod600/etc/vsftpd/vsftpd_login.db

  [root@benet01~]#ls-l/etc/vsftpd/vsftpd_login.db

  -rw------- 1rootroot12288May2612:

54/etc/vsftpd/vsftpd_login.db

  3、建立虚拟用户所需的PAM配置文件.

  在"/etc/pam.d"目录中建立vsftpd虚拟用户身份认证所需的PAM配置文件,名称为vsftpd.vu.

  #vi/etc/pam.d/vsftpd.vu

  authrequired/lib/security/pam_userdb.sodb=/etc/vsftpd/vsftpd_login

  accountrequired/lib/security/pam_userdb.sodb=/etc/vsftpd/vsftpd_login

  #cat/etc/pam.d/vsftpd.vu

  authrequired/lib/security/pam_userdb.sodb=/etc/vsftpd/vsftpd_login

  accountrequired/lib/security/pam_userdb.sodb=/etc/vsftpd/vsftpd_login

  4、建立虚拟用户及所要访问的目录并设置相应权限.

  建立vsftpd虚拟用户所需的系统用户账号,账号为zhen,指定用户的宿主目是"/home/ftpsite/",设置宿主目录的权限是700(vsftpd服务器中的所有虚拟用户账号登录后都将在"/home/ftpsite"目录中)

  #useradd-d/home/ftpsitezhen

  #chmod700/home/ftpsite

  5、设置vsftpd.conf配置文件

  在对vsftpd.conf配置文件修改前,先将它原来的文件备份,以便出现配置错误时可进行恢复.

  #cd/etc/vsftpd

  #cpvsftpd.confvsftpd.conf.bak

  在vsftpd.conf配置文件添加虚拟用户的配置项:

  guest_enable=yes

  guest_username=zhen

  pam_service_name=vsftpd.vu

  所有配置完成后,重新启动vsftpd服务程序

  #servicevsftpdrestart

  Shuttingdownvsftpd:

[ OK ]

  Startingvsftpdforvsftpd:

[ OK ]

  可以对不同的用户设置不同的权限.

  vsftpd服务器中的虚拟用户可以灵活的针对不同的用户账号设置不同的用户权限:

  1、设置主配置文件

  在vsftpd配置文件中添加user_config_dir配置项,并设置用户配置文件的保存路径

  user_config_dir=/etc/vsftpd_user_conf(设置在"/etc/vsftpd_user_conf"目录中保存虚拟用户的配置文件.)

  2、建立用户配置文件目录

  #mkdir/etc/vsftpd_user_conf

  3、为虚拟目录建立单独的配置文件

  为用户建立独立的配置文件,配置文件名称和用户名相同,并给他相应的权限.

  #vi/etc/vsftpd_user_conf/rr

  anon_world_readable_only=no //表示用户可以浏览ftp目录和下载文件.

  #ftp172.16.16.121

  Connectedto172.16.16.121.

  220(vsFTPd2.0.1)

  530PleaseloginwithUSERandPASS.

  530PleaseloginwithUSERandPASS.

  KERBEROS_V4rejectedasanauthenticationtype

  Name(172.16.16.121:

root):

rr

  331Pleasespecifythepassword.

  Password:

  230Loginsuccessful.

  RemotesystemtypeisUNIX.

  Usingbinarymodetotransferfiles.

  ftp>ls

  227EnteringPassiveMode(172,16,16,121,250,156)

  150Herecomesthedirectorylisting.

  -rw-r--r--   10       0             29May2605:

2744.txt

  -rw-r--r--   10       0              0May2605:

3055.txt

  -rw-r--r--   1503     503            0May2605:

24afile

  -rw-r--r--   1503     503            0May2606:

10file01

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1