{"id":216243,"date":"2021-04-22T09:20:53","date_gmt":"2021-04-22T01:20:53","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=216243"},"modified":"2021-04-16T14:22:01","modified_gmt":"2021-04-16T06:22:01","slug":"centos8-vsftpd-ftps","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/centos8-vsftpd-ftps.html","title":{"rendered":"Centos8\u4e2d\u4f7f\u7528VSFTPD\u914d\u7f6eFTPs"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u672c\u6587\u4e2d\uff0c\u5c06\u6f14\u793a\u5982\u4f55\u5b89\u88c5vsftpd\u670d\u52a1\uff0c\u914d\u7f6e\u4e3aftps\uff0c\u5e76\u4e3aftp\u7528\u6237\u914d\u7f6echroot\uff0c\u5c06ftp\u4f1a\u8bdd\u9650\u5236\u5728\u5404\u81ea\u7684\/var\/www\/html\/[username]\u76ee\u5f55\u4e2d\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u7cfb\u7edf\u73af\u5883<\/strong><\/div>\n

Centos8<\/p>\n

\u521b\u5efa\u7528\u6237<\/strong><\/div>\n

\u9700\u8981\u521b\u5efa\u7528\u4e8e\u8bbf\u95eeFTP\u670d\u52a1\u5668\u7684\u7528\u6237\u3002\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u7528\u6237\u5e76\u8bbe\u7f6e\u5404\u81ea\u7684\u5bc6\u7801\uff0c\u521b\u5efa\u7528\u6237\u65f6\u4f7f\u7528-s<\/code>\u9009\u9879\uff0c\u8ba9\u8fd9\u4e24\u4e2a\u7528\u6237\u7981\u6b62shell\u767b\u5f55\uff1a<\/p>\n

\r\n[root@localhost ~]# useradd -s \/sbin\/nologin user01\r\n[root@localhost ~]# useradd -s \/sbin\/nologin user02\r\n[root@localhost ~]# echo '123'|passwd --stdin user01\r\nChanging password for user user01.\r\npasswd: all authentication tokens updated successfully.\r\n[root@localhost ~]# echo '123'|passwd --stdin user02\r\nChanging password for user user02.\r\npasswd: all authentication tokens updated successfully.\r\n<\/pre>\n

\"\"<\/p>\n

\u7f16\u8f91\/etc\/shells\u914d\u7f6e\u6587\u4ef6<\/strong><\/div>\n

\u4e0a\u9762\u7684\u7528\u6237\u7684shell\u8bbe\u7f6e\u4e3a\/sbin\/nologin<\/code>\u4e4b\u540e\uff0c\u9700\u8981\u5728\/etc\/shells<\/code>\u6587\u4ef6\u4e2d\u6dfb\u52a0\/sbin\/nologin<\/code>\uff0c\u5426\u5219\u540e\u9762ftp\u7528\u6237\u767b\u5f55\u65f6\u63d0\u793aLogin failed: 530 Login incorrect.<\/code><\/p>\n

\r\n[root@localhost ~]# echo \"\/sbin\/nologin\" >> \/etc\/shells \r\n[root@localhost ~]# cat \/etc\/shells \r\n\/bin\/sh\r\n\/bin\/bash\r\n\/usr\/bin\/sh\r\n\/usr\/bin\/bash\r\n\/sbin\/nologin\r\n<\/pre>\n
\u5b89\u88c5VSFTPD<\/strong><\/div>\n

\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u5b89\u88c5vsftpd\uff1a<\/p>\n

\r\n[root@localhost ~]# yum -y install vsftpd\r\n<\/pre>\n

\"\"<\/p>\n

\u521b\u5efa\u81ea\u7b7e\u540d\u8bc1\u4e66<\/strong><\/div>\n

\u4e3aFTP\u670d\u52a1\u5668\u521b\u5efa\u4e00\u4e2a\u81ea\u7b7e\u540d\u8bc1\u4e66\u3002\u4f7f\u7528openssl<\/code>\u547d\u4ee4\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u751f\u6210\u81ea\u7b7e\u540d\u8bc1\u4e66\u548c\u79c1\u94a5\uff1a<\/p>\n

\r\n[root@localhost ~]# openssl req -x509 -nodes -keyout \/etc\/vsftpd\/vsftpd.key -out \/etc\/vsftpd\/vsftpd.pem -days 365 -newkey rsa:2048\r\nGenerating a RSA private key\r\n..+++++\r\n..............................................+++++\r\nwriting new private key to '\/etc\/vsftpd\/vsftpd.key'\r\n-----\r\nYou are about to be asked to enter information that will be incorporated\r\ninto your certificate request.\r\nWhat you are about to enter is what is called a Distinguished Name or a DN.\r\nThere are quite a few fields but you can leave some blank\r\nFor some fields there will be a default value,\r\nIf you enter '.', the field will be left blank.\r\n-----\r\nCountry Name (2 letter code) [XX]:CN\r\nState or Province Name (full name) []:Shandong\r\nLocality Name (eg, city) [Default City]:QD\r\nOrganization Name (eg, company) [Default Company Ltd]:Linuxprobe\r\nOrganizational Unit Name (eg, section) []:\r\nCommon Name (eg, your name or your server's hostname) []:ftp.lrxjmw.cn\r\nEmail Address []:\r\n<\/pre>\n

\"\"<\/p>\n

\u914d\u7f6eVSFTPD\u670d\u52a1\u652f\u6301chroot\u548cSSL<\/strong><\/div>\n

\u5c06\u4e0a\u9762\u521b\u5efa\u7684\u7528\u6237user01\u548cuser02\u6dfb\u52a0\u5230\/etc\/vsftpd\/user_list<\/code>\u6587\u4ef6\u4e2d\uff0c\u53ea\u5141\u8bb8\u8be5\u6587\u4ef6\u4e2d\u7684\u7528\u6237ftp\u767b\u5f55\u3002<\/p>\n

\r\n[root@localhost vsftpd]# vim \/etc\/vsftpd\/user_list \r\n\r\n# vsftpd userlist\r\n# If userlist_deny=NO, only allow users in this file\r\n# If userlist_deny=YES (default), never allow users in this file, and\r\n# do not even prompt for a password.\r\n# Note that the default vsftpd pam config also checks \/etc\/vsftpd\/ftpusers\r\n# for users that are denied.\r\nroot\r\nbin\r\ndaemon\r\nadm\r\nlp\r\nsync\r\nshutdown\r\nhalt\r\nmail\r\nnews\r\nuucp\r\noperator\r\ngames\r\nnobody\r\nuser01\r\nuser02\r\n<\/pre>\n

\"\"
\n\u4e0b\u9762\u7f16\u8f91\/etc\/vsftpd\/vsftpd.conf<\/code>\uff0c\u7f16\u8f91\u524d\u9700\u8981\u5907\u4efd\u4e00\u4e0b\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n

\r\n[root@localhost vsftpd]# cd \/etc\/vsftpd\/\r\n[root@localhost vsftpd]# cp -p vsftpd.conf vsftpd.conf.back\r\n<\/pre>\n

\u7f16\u8f91vsftpd.conf\u6587\u4ef6\uff0c\u914d\u7f6e\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n

\r\n[root@localhost vsftpd]# vim vsftpd.conf\r\n[root@localhost vsftpd]# cat vsftpd.conf | grep -Ev '(^$|^#)'\r\nanonymous_enable=NO\r\nlocal_enable=YES\r\nwrite_enable=YES\r\nlocal_umask=022\r\ndirmessage_enable=YES\r\nxferlog_enable=YES\r\nconnect_from_port_20=YES\r\nxferlog_std_format=YES\r\nlisten=NO\r\nlisten_ipv6=YES\r\npam_service_name=vsftpd\r\nuserlist_enable=YES\r\nuserlist_deny=NO\r\nssl_enable=YES\r\nssl_sslv2=NO\r\nssl_sslv3=NO\r\nssl_tlsv1_2=YES\r\nrsa_cert_file=\/etc\/vsftpd\/vsftpd.pem\r\nrsa_private_key_file=\/etc\/vsftpd\/vsftpd.key\r\nallow_anon_ssl=NO\r\nforce_local_data_ssl=YES\r\nforce_local_logins_ssl=YES\r\nrequire_ssl_reuse=NO\r\nssl_ciphers=HIGH\r\npasv_min_port=30000\r\npasv_max_port=31000\r\ndebug_ssl=YES\r\nchroot_local_user=YES\r\nlocal_root=\/var\/www\/html\/$USER\r\nallow_writeable_chroot=YES\r\n<\/pre>\n

\"\"<\/p>\n

\u5f00\u542f\u670d\u52a1<\/strong><\/div>\n

\u4e0b\u9762\u542f\u7528\u670d\u52a1\uff0c\u5e76\u542f\u52a8\u670d\u52a1\uff1a<\/p>\n

\r\n[root@localhost ~]# systemctl enable vsftpd\r\nCreated symlink \/etc\/systemd\/system\/multi-user.target.wants\/vsftpd.service \u00a1\u00fa \/usr\/lib\/systemd\/system\/vsftpd.service.\r\n[root@localhost ~]# systemctl start vsftpd\r\n<\/pre>\n

\"\"<\/p>\n

\u8bbe\u7f6e\u9632\u706b\u5899<\/strong><\/div>\n
\r\n[root@localhost ~]# firewall-cmd --permanent --add-service=ftp\r\nsuccess\r\n[root@localhost ~]# firewall-cmd --reload\r\nsuccess\r\n<\/pre>\n

\"\"<\/p>\n

\u8bbe\u7f6eSELinux<\/strong><\/div>\n

\u4e0b\u9762\u9700\u8981\u8bbe\u7f6e\u4e00\u4e0bselinux\u7684boolean\u503c\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\/var\/www\/html<\/code>\u76ee\u5f55\u7684\u5b89\u5168\u4e0a\u4e0b\u6587\u4e3ahttpd_sys_content_t<\/code>\uff0c\u7528\u6237\u4f7f\u7528ftp\u4e0a\u4f20\u4e0b\u8f7d\u53ef\u80fd\u4f1a\u51fa\u73b0\u6743\u9650\u95ee\u9898\uff0c\u6240\u4ee5\u4e0b\u9762\u8bbe\u7f6e\u4e00\u4e0b\u548cftp\u76f8\u5173\u7684selinux\u8bbe\u7f6e\uff1a<\/p>\n

\r\n[root@localhost ~]# setsebool -P ftpd_full_access 1\r\n[root@localhost ~]# getsebool ftpd_full_access\r\nftpd_full_access --> on\r\n<\/pre>\n
\u521b\u5efaftp\u7528\u6237\u7684\u76ee\u5f55<\/strong><\/div>\n

\u5728\/var\/www\/html<\/code>\u76ee\u5f55\u4e2d\u521b\u5efa\u7528\u6237\u7684\u76ee\u5f55\uff0c\u5e76\u8bbe\u7f6e\u6743\u9650\u3002<\/p>\n

\r\n[root@localhost ~]# mkdir \/var\/www\/html\/user0{1..2}\r\n[root@localhost ~]# chown -R user01:apache \/var\/www\/html\/user01\/\r\n[root@localhost ~]# chown -R user02:apache \/var\/www\/html\/user02\/\r\n<\/pre>\n

\"\"
\n\u5728\u6bcf\u4e2a\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u7a7a\u6587\u4ef6\u3002\u4f60\u5728\u767b\u5f55\u540e\u53ef\u4ee5\u533a\u5206\u7528\u6237\u5bb6\u76ee\u5f55\uff1a<\/p>\n

\r\n[root@localhost ~]# touch \/var\/www\/html\/user01\/user01_files\r\n[root@localhost ~]# touch \/var\/www\/html\/user02\/user02_files\r\n<\/pre>\n

\"\"<\/p>\n

\u8bbf\u95eeftp\u670d\u52a1\u5668<\/strong><\/div>\n

\u4e0b\u8f7dlftp<\/code>\u547d\u4ee4\u884c\u5ba2\u6237\u7aef\u8fdb\u884c\u8fde\u63a5\u6d4b\u8bd5\uff1a<\/p>\n

\r\n[root@localhost ~]# yum -y install lftp\r\n<\/pre>\n

\"\"
\n\u4e0b\u9762\u4f7f\u7528user01\u767b\u5f55\uff1a<\/p>\n

\r\n[root@localhost ~]# lftp user01@localhost\r\nPassword: \r\nlftp user01@localhost:~> ls                   \r\nls: Fatal error: Certificate verification: Not trusted (01:3E:A2:1B:39:E9:BE:DB:55:1F:C3:71:34:6F:B6:8E:E2:D0:2C:8C)\r\n<\/pre>\n

\u4e0a\u9762\u63d0\u793a\u9519\u8bef\uff0c\u56e0\u4e3a\u662f\u81ea\u7b7e\u540d\u8bc1\u4e66\u3002\u53ef\u4ee5\u901a\u8fc7\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u4e0d\u68c0\u67e5\u8bc1\u4e66\uff1a<\/p>\n

\r\n[root@localhost ~]# echo \"set ssl:verify-certificate no\" >> \/etc\/lftp.conf \r\n<\/pre>\n

\u4e0b\u9762\u518d\u6267\u884c\u4e00\u4e0blftp\u547d\u4ee4\u4f7f\u7528user01\u767b\u5f55\uff1a<\/p>\n

\r\n[root@localhost ~]# lftp user01@localhost\r\nPassword: \r\nlftp user01@localhost:~> ls                   \r\n-rw-r--r--    1 0        0               0 Apr 07 09:42 user01_files\r\n<\/pre>\n

\"\"
\n\u518d\u4f7f\u7528user02\u767b\u5f55\u770b\u4e00\u4e0b\uff1a<\/p>\n

\r\n[root@localhost ~]# lftp user02@localhost\r\nPassword: \r\nlftp user02@localhost:~> ls                   \r\n-rw-r--r--    1 0        0               0 Apr 07 09:42 user02_files\r\n<\/pre>\n

\"\"<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u8bbe\u7f6e\u66f4\u5b89\u5168\u7684ftp - \u201cFTPs\u201d\u3001\u5c06ftp\u7528\u6237\u7684\u4e3b\u76ee\u5f55\u9650\u5236\u5728\/var\/www\/html\u76ee\u5f55\u4e2d\u3001\u5982\u4f55\u4f7f\u7528\u8f7b\u91cf\u5316ftp\u547d\u4ee4\u884c\u5de5\u5177 - \u201clftp\u201d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Centos8 \u9700\u8981\u521b\u5efa\u7528\u4e8e\u8bbf\u95eeFTP\u670d\u52a1\u5668\u7684\u7528\u6237\u3002\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u7528\u6237\u5e76\u8bbe\u7f6e\u5404\u81ea\u7684\u5bc6\u7801\uff0c\u521b\u5efa\u7528\u6237\u65f6\u4f7f\u7528-s […]<\/p>\n","protected":false},"author":309,"featured_media":216244,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-216243","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/216243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=216243"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/216243\/revisions"}],"predecessor-version":[{"id":216257,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/216243\/revisions\/216257"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/216244"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=216243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=216243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=216243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}