首页 运维 正文
CentOS下配置vsftpd

 2022-10-23    401  

  1、通过YUM安装必需的vsftpd, pam, pam-devel;

  2、通过编译安装必需的pam_mysql(下面附件里);

CentOS下配置vsftpd

  3、修改默认vsftpd配置文件 (/etc/vsftpd/vsftpd.conf)以及添加ftp用户的权限配置文件(/etc/vsftpd/vconf/);

  4、添加虚拟系统用户,及其ftp用户登录认证数据库;

  5、修改vsftpd默认的pam配置文件 (/etc/pam.d/vsftpd);

  6、添加ftp端口到防火墙,重启vsftpd服务,测试ftp虚拟用户登录。

  1)

  [simonsun@magic~]$sudoyuminstallvsftpdpampam-devel 

  目前的版本为

  vsftpd – 2.0.5-12.el5, pam – 0.99.6.2-3.27.el5, pam-devel – 0.99.6.2-3.27.el5。

  2)

  [simonsun@magic~]$wgethttp://prdownloads.sourceforge.net/pam-mysql/pam_mysql-0.7RC1.tar.gz 

  [simonsun@magic~]$tarzxvfpam_mysql-0.7RC1.tar.gz 

  [simonsun@magic~]$lspam_mysql-0.7RC1 

  acinclude.m4config.guessconfigureCREDITSltmain.shmissingpam_mysql.cpkg.m4 

  aclocal.m4config.h.inconfigure.inINSTALLMakefile.ammkinstalldirspam_mysql.specREADME 

  ChangeLogconfig.subCOPYINGinstall-shMakefile.inNEWSpam_mysql.spec.instamp-h.in 

  [simonsun@magic~]$vimpam_mysql-0.7RC1/configure 

  #修改configure中的一个bug,将下面的一段修改,加上#include ,原来没有此引用。

  =================================

  #include 

  #include 

  int 

  main() 

  { 

  md5_calc(0,0,0); 

  ; 

  return0; 

  } 

  =================================

  [simonsun@magic~]$cdpam_mysql-0.7RC1 

  [simonsun@magicpam_mysql-0.7RC1]$./configure 

  [simonsun@magicpam_mysql-0.7RC1]$make 

  [simonsun@magicpam_mysql-0.7RC1]$sudomakeinstall 

  [simonsun@magicpam_mysql-0.7RC1]$sudocp/usr/lib/security/pam_mysql.*/lib/security/ 

  3)

  [simonsun@magic~]$sudovim/etc/vsftpd/vsftpd.conf 

  ======================================

  anonymous_enable=NO

  local_enable=YES

  write_enable=YES

  local_umask=022

  #anon_upload_enable=YES

  #anon_mkdir_write_enable=YES

  dirmessage_enable=YES

  xferlog_enable=YES

  connect_from_port_20=YES

  #chown_uploads=YES

  #chown_username=whoever

  xferlog_file=/var/log/vsftpd.log 

  xferlog_std_format=YES

  #idle_session_timeout=600

  #data_connection_timeout=120

  #nopriv_user=ftpsecure

  #async_abor_enable=YES

  #ascii_upload_enable=YES

  #ascii_download_enable=YES

  ftpd_banner=WelcometoMagicLinuxFTPservice. 

  #deny_email_enable=YES

  #(defaultfollows) 

  #banned_email_file=/etc/vsftpd/banned_emails 

  chroot_local_user=YES

  #chroot_list_enable=YES

  #(defaultfollows) 

  #chroot_list_file=/etc/vsftpd/chroot_list 

  #ls_recurse_enable=YES

  listen=YES

  listen_port=21

  #listen_ipv6=YES

  #下面是添加的:

  guest_enable=YES

  guest_username=vvsftpd#虚拟系统用户,在步骤4)中添加该用户到系统用户中。 

  user_config_dir=/etc/vsftpd/vconf/#登录ftp的虚拟用户的权限配置文件。 

  pam_service_name=vsftpd

  userlist_enable=YES

  tcp_wrappers=YES

  ======================================

  [simonsun@magic~]$sudomkdir/etc/vsftpd/vconf/ 

  [simonsun@magic~]$sudovim/etc/vsftpd/vconf/myftp 

  ======================================

  write_enable=YES

  anon_upload_enable=YES

  anon_mkdir_write_enable=YES

  anon_world_readable_only=NO

  ======================================

  4)

  [simonsun@magic~]$sudo/usr/sbin/useradd-d/home/vvsftpd-s/sbin/nologinvvsftpd 

  [simonsun@magic~]$mysql-uroot-p 

  #执行如下语句,为虚拟系统用户vvsftpd创建虚拟用户(如myftp)登录ftp时的认证数据库vsftpd

  ====================================== 

  createdatabasevsftpd; 

  usevsftpd; 

  createtableuser(namechar(20)binary,passwdchar(20)binary); 

  insertintouservalues('myftp',ENCRYPT('ptfym')); 

  grantselectonvsftpd.usertovvsftpd@localhostidentifiedby'PaSsWoRd'; 

  flushprivileges; 

  ====================================== 

  5)

  [simonsun@magic~]$sudovim/etc/pam.d/vsftpd 

  修改成如下

  ====================================== 

  #%PAM-1.0 

  sessionoptionalpam_keyinit.soforcerevoke 

  authrequiredpam_listfile.soitem=usersense=denyfile=/etc/vsftpd/ftpusersnerr=succeed

  #authrequiredpam_shells.so 

  authrequired/lib/security/pam_mysql.souser=vvsftpdpasswd=PaSsWoRdhost=localhostdb=vsftpdtable=userusercolumn=namepasswdpasswdcolumn=passwdcrypt=1

  accountrequired/lib/security/pam_mysql.souser=vvsftpdpasswd=PaSsWoRdhost=localhostdb=vsftpdtable=userusercolumn=namepasswdpasswdcolumn=passwdcrypt=1

  #authincludesystem-auth 

  #accountincludesystem-auth 

  sessionincludesystem-auth 

  sessionrequiredpam_loginuid.so 

  ====================================== 

  6)

  [simonsun@magic~]$sudo/sbin/iptables-IINPUT-ptcp--dport20-jACCEPT 

  [simonsun@magic~]$sudo/sbin/iptables-IINPUT-ptcp--dport21-jACCEPT 

  [simonsun@magic~]$sudo/etc/rc.d/init.d/iptablessave 

  [simonsun@magic~]$sudo/etc/rc.d/init.d/iptablesrestart 

  清除防火墙规则: [确定]

  把 chains 设置为 ACCEPT 策略:filter nat [确定]

  正在卸载 Iiptables 模块: [确定]

  应用 iptables 防火墙规则: [确定]

  载入额外 iptables 模块:ip_conntrack_netbios_ns [确定]

  [simonsun@magic~]$sudo/etc/rc.d/init.d/vsftpdrestart 

  关闭 vsftpd: [确定]

  为 vsftpd 启动 vsftpd: [确定]

  [simonsun@magic~]$ftpshellfisher.3322.org 

  Connectedtoshellfisher.3322.org. 

  220WelcometoMagicLinuxFTPservice. 

  530PleaseloginwithUSERandPASS. 

  530PleaseloginwithUSERandPASS. 

  KERBEROS_V4rejectedasanauthenticationtype 

  Name(shellfisher.3322.org:simonsun):myftp 

  331Pleasespecifythepassword. 

  Password: 

  230Loginsuccessful. 

  RemotesystemtypeisUNIX. 

  Usingbinarymodetotransferfiles. 

  ftp>ls 

  227EnteringPassiveMode(221,215,250,110,86,88) 

  150Herecomesthedirectorylisting. 

  226DirectorysendOK. 

  ftp>mkdirtestftp 

  257"/testftp"created 

  ftp>ls 

  227EnteringPassiveMode(221,215,250,110,43,155) 

  150Herecomesthedirectorylisting. 

  drwx------25075094096Mar2408:32testftp 

  226DirectorysendOK. 

  ftp>quit 

  221Goodbye. 

  ====================================== 

原文链接:https://77isp.com/post/8819.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。