{"id":104078,"date":"2024-09-16T18:33:10","date_gmt":"2024-09-16T10:33:10","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=104078"},"modified":"2024-09-16T18:33:10","modified_gmt":"2024-09-16T10:33:10","slug":"centos7-sftp-server","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/centos7-sftp-server.html","title":{"rendered":"CentOS7 configuration uses the SFTP server"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nSFTP\uff0c\u5373 SSH \u6587\u4ef6\u4f20\u8f93\u534f\u8bae\uff08 SSH File Transfer Protocol \uff09\uff0c\u6216\u8005\u8bf4\u662f\u5b89\u5168\u6587\u4ef6\u4f20\u8f93\u534f\u8bae\uff08 Secure File Transfer Protocol \uff09\u3002SFTP \u662f\u4e00\u4e2a\u72ec\u7acb\u7684 SSH \u5c01\u88c5\u534f\u8bae\u5305\uff0c\u901a\u8fc7\u5b89\u5168\u8fde\u63a5\u4ee5\u76f8\u4f3c\u7684\u65b9\u5f0f\u5de5\u4f5c\u3002\u5b83\u7684\u4f18\u52bf\u5728\u4e8e\u53ef\u4ee5\u5229\u7528\u5b89\u5168\u7684\u8fde\u63a5\u4f20\u8f93\u6587\u4ef6\uff0c\u8fd8\u80fd\u6d4f\u89c8\u672c\u5730\u548c\u8fdc\u7a0b\u7cfb\u7edf\u4e0a\u7684\u6587\u4ef6\u7cfb\u7edf\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5728\u5f88\u591a\u60c5\u51b5\u4e0b\uff0cSFTP\u90fd\u6bd4FTP\u66f4\u53ef\u53d6\uff0c\u56e0\u4e3a\u5b83\u5177\u6709\u6700\u57fa\u672c\u7684\u5b89\u5168\u7279\u6027\u548c\u80fd\u5229\u7528 SSH \u8fde\u63a5\u7684\u80fd\u529b\uff0cFTP\u662f\u4e00\u79cd\u4e0d\u5b89\u5168\u7684\u534f\u8bae\uff0c\u53ea\u80fd\u5728\u6709\u9650\u7684\u60c5\u51b5\u4e0b\u6216\u5728\u60a8\u4fe1\u4efb\u7684\u7f51\u7edc\u4e0a\u4f7f\u7528\u3002<\/p>\n

\u5148\u51b3\u6761\u4ef6\uff1a<\/p>\n

\u670d\u52a1\u5668 OpenSSH-Server \u7248\u672c\u6700\u4f4e4.8p1\uff0c\u56e0\u4e3a\u914d\u7f6e\u6743\u9650\u9700\u8981\u7248\u672c\u6dfb\u52a0\u7684\u65b0\u914d\u7f6e\u9879 ChrootDirectory \u6765\u5b8c\u6210\u3002<\/p>\n

\u5982\u4f55\u67e5\u770bOpenSSH\u7248\u672c\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n

\r\n$ ssh -V\r\nOpenSSH_6.6.1p1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\n<\/pre>\n
\u521b\u5efa\u7528\u6237\u4fe1\u606f<\/strong><\/span><\/div>\n
\r\n\u6dfb\u52a0\u7528\u6237\u7ec4\uff1a\r\n\r\n$ groupadd sftp\r\n\r\n\u6dfb\u52a0\u7528\u6237\uff1a\r\n\r\n$ useradd -g sftp -s \/sbin\/nologin -M userrenwolecom\r\n\r\n\u53c2\u6570\u6ce8\u89e3\uff1a\r\n\r\n-g              # \u52a0\u5165\u7528\u6237\u7ec4\r\n-s              # \u6307\u5b9a\u7528\u6237\u767b\u5165\u540e\u6240\u4f7f\u7528\u7684shell\r\n\/sbin\/nologin   # \u7528\u6237\u4e0d\u5141\u8bb8\u767b\u5f55\r\n-M              # \u4e0d\u8981\u81ea\u52a8\u5efa\u7acb\u7528\u6237\u7684\u767b\u5165\u76ee\u5f55\r\n\r\n\u8bbe\u7f6e\u7528\u6237\u5bc6\u7801\uff1a\r\n\r\n$ passwd userrenwolecom\r\n<\/pre>\n
\u521b\u5efa\u7528\u6237\u76ee\u5f55\u5e76\u8bbe\u7f6e\u6743\u9650<\/strong><\/span><\/div>\n
\r\n\u521b\u5efasftp\u4e3b\u76ee\u5f55\uff1a\r\n\r\n$ mkdir \/data\/sftp\r\n\r\n\u8bbe\u7f6esftp\u4e3b\u76ee\u5f55\u6743\u9650\uff1a\r\n\r\n$ chown root:sftp \/data\/sftp\r\n\r\n\u6587\u4ef6\u5939\u6240\u6709\u8005\u5fc5\u987b\u662froot\uff0c\u7528\u6237\u7ec4\u53ef\u4ee5\u4e0d\u662froot\u3002\r\n\r\n$ chmod 744 \/data\/sftp\r\n\r\n\u6743\u9650\u4e0d\u80fd\u8d85\u8fc7755\u4f46\u4e0d\u5305\u62ec755\uff0c\u5426\u5219\u4f1a\u5bfc\u81f4\u767b\u5f55\u62a5\u9519\u3002\r\n\r\n<\/pre>\n
\u521b\u5efa\u4e0a\u4f20\u76ee\u5f55\u5e76\u8bbe\u7f6e\u6743\u9650<\/strong><\/span><\/div>\n

\u5728\/data\/sftp\/\u4e3b\u76ee\u5f55\u4e0b\u521b\u5efauploads\u8d44\u6599\u5939\uff0c\u5e76\u8bbe\u7f6e\u6240\u6709\u8005\u662f\uff1auserrenwolecom\uff0c\u7528\u6237\u7ec4\u96b6\u5c5e\uff1asftp\uff0c\u8fd9\u6837\u65b0\u589e\u7684\u5e10\u53f7\u624d\u80fd\u6709\u4e0a\u4f20\u7f16\u8f91\u7684\u6743\u9650\u3002<\/p>\n

\r\n$ mkdir -p \/data\/sftp\/uploads\r\n$ chown userrenwolecom:sftp \/data\/sftp\/uploads\r\n<\/pre>\n
\u4fee\u6539sshd_config\u914d\u7f6e\u6587\u4ef6<\/strong><\/span><\/div>\n
\r\n$ vim \/etc\/ssh\/sshd_config\r\n\r\n\u5c06\u6b64\u884c\u6ce8\u91ca\u6389\uff0c\u4f8b\u5982\uff1a\r\n\r\n#Subsystem sftp \/usr\/libexec\/openssh\/sftp-server\r\n\r\n\u5728\u6b64\u884c\u4e0b\u9762\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\uff1a\r\n\r\nSubsystem sftp internal-sftp       # \u6307\u5b9a\u4f7f\u7528sftp\u670d\u52a1\u4f7f\u7528\u7cfb\u7edf\u81ea\u5e26\u7684internal-sftp\r\nMatch Group sftp                   # \u5339\u914dsftp\u7ec4\u7684\u7528\u6237,\u82e5\u8981\u5339\u914d\u591a\u4e2a\u7ec4,\u53ef\u7528\u9017\u53f7\u5206\u5f00\r\nChrootDirectory \/data\/sftp\/        # \u9650\u5236\u7528\u6237\u7684\u6839\u76ee\u5f55\r\nForceCommand internal-sftp         # \u53ea\u80fd\u7528\u4e8esftp\u767b\u5f55\r\nAllowTcpForwarding no              # \u7981\u6b62\u7528\u6237\u4f7f\u7528\u7aef\u53e3\u8f6c\u53d1\r\nX11Forwarding no                   # \u7981\u6b62\u7528\u6237\u4f7f\u7528\u7aef\u53e3\u8f6c\u53d1\r\n<\/pre>\n
\u91cd\u542fSSH\u670d\u52a1<\/strong><\/span><\/div>\n
\r\n$ systemctl restart sshd\r\n<\/pre>\n
\u6d4b\u8bd5\u662f\u5426\u80fd\u591f\u767b\u5f55\u3001\u4e0a\u4f20\u3001\u4e0b\u8f7d\u7b49\u64cd\u4f5c<\/strong><\/span><\/div>\n

\u572810.28.204.61\u670d\u52a1\u5668\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u767b\u5f55\uff1a<\/p>\n

\r\n$ sftp -P 12012 userrenwolecom@10.28.204.62\r\nuserrenwolecom@10.28.204.62's password:\r\npacket_write_wait: Connection to 10.28.204.62 port 12012: Broken pipe\r\nCouldn't read packet: Connection reset by peer\r\n<\/pre>\n

\u62a5\u9519\uff0c\u6b64\u95ee\u9898\u662f\u7531\u4e8e\/data\/sftp \u76ee\u5f55\u6743\u9650\u5206\u914d\u4e0d\u5f53\u6240\u81f4\uff0c\u5c06\u6b64\u76ee\u5f55\u7684\u6240\u6709\u8005\u66f4\u6539\u4e3aroot\u5373\u53ef\uff0c\u7528\u6237\u7ec4\u53efroot\/sftp\u3002<\/p>\n

\u518d\u6b21\u6d4b\u8bd5\u8fde\u63a5\uff1a<\/p>\n

\r\n$ sftp -P 12012 userrenwolecom@10.28.204.62\r\nThe authenticity of host '[10.28.204.62]:12012 ([10.28.204.62]:12012)' can't be established.\r\nECDSA key fingerprint is SHA256:\/YI\/L4RT1QH7lkfxMCAkKnvniQslyUl15mOUKUo8K3k.\r\nECDSA key fingerprint is MD5:6d:b6:f3:93:8e:48:53:24:9d:5d:c2:2a:5f:28:f4:d2.\r\nAre you sure you want to continue connecting (yes\/no)? YES\r\nWarning: Permanently added '[10.28.204.62]:12012' (ECDSA) to the list of known hosts.\r\nuserrenwolecom@10.28.204.62's password:\u3010\u8f93\u5165userrenwolecom\u7528\u6237\u5bc6\u7801\u56de\u8f66\u3011\r\nConnected to 10.28.204.62.\r\nsftp>\r\n<\/pre>\n

\u8fde\u63a5\u6210\u529f\uff0c\u73b0\u5728\u6d4b\u8bd5\u4e0a\u4f20\u4e00\u4e2a\u6587\u4ef6\u523010.28.204.62\u670d\u52a1\u5668<\/p>\n

\r\n\u4e0a\u4f20\r\n\r\nsftp> put \/tmp\/nginx_log_stat \/uploads\r\nUploading \/tmp\/nginx_log_stat to \/uploads\/nginx_log_stat\r\n\/tmp\/nginx_log_stat\r\n\r\n\u4e0b\u8f7d\r\n\r\nsftp> get uploads\/nginx_log_stat \/mnt\r\nFetching \/uploads\/nginx_log_stat to \/mnt\/nginx_log_stat\r\n\/uploads\/nginx_log_stat   100%    7   1.1KB\/s   00:00\r\nsftp>\r\n\r\n\u5220\u9664\r\n\r\nsftp> rm \/uploads\/nginx_log_stat\r\nRemoving \/uploads\/nginx_log_stat\r\n\r\n\u66f4\u591a\u547d\u4ee4\u8bf7\u53c2\u9605\uff1a\r\n\r\nsftp> help\r\n<\/pre>\n
\u5c0f\u7ed3\uff1a<\/strong><\/span><\/div>\n

\u5728\u914d\u7f6e\u8fc7\u7a0b\u4e2d\u9047\u5230\u6bd4\u8f83\u5947\u602a\u7684\u95ee\u9898\uff0c\u6211\u5c06 sshd_config \u914d\u7f6e\u6587\u4ef6\u4e2d\u7684 Match Group sftp \u4fee\u6539\u4e3a Match User userrenwolecom \uff0c\u91cd\u542fsshd\u540e\uff0c\u5f53\u524d\u7ec8\u7aef\u4e0d\u4f1a\u65ad\u5f00\uff0c\u65b0\u5efa\u7ec8\u7aef\u8f93\u5165\u6b63\u786e\u5bc6\u7801\u540e\u4f1a\u51fa\u73b0SSH\u767b\u5f55\u95ea\u9000\uff08\u81ea\u52a8\u5173\u95ed\u7ec8\u7aef\uff09\u95ee\u9898\uff0c\u4e0d\u7ba1\u662f\u7528PUTTY\u8fd8\u662fXshell\u5747\u662f\u5982\u6b64\uff0c\u540e\u6765\u6211\u5c06\u7528\u6237\u4fee\u6539\u6210\u7ec4\u540e\u5c31\u6b63\u5e38\u4e86\uff0c\u5177\u4f53\u539f\u56e0\u5c1a\u672a\u53ef\u77e5\uff0c\u4e0d\u8fc7\u4fee\u6539\u4e3a\u7ec4\u6548\u679c\u662f\u4e00\u6837\u7684\u3002\u5982\u679c\u4f60\u77e5\u9053\u4ec0\u4e48\u539f\u56e0\u8fd8\u8bf7\u6307\u6559\u3002<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/renwole.com\/archives\/951<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttps:\/\/lrxjmw.cn\/centos7-sftp-server.html<\/a>\u7f16\u8f91\uff1a\u4f55\u4e91\u8273\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb SFTP\uff0c\u5373 SSH \u6587\u4ef6\u4f20\u8f93\u534f\u8bae\uff08 SSH File Transfer Protocol \uff09\uff0c\u6216\u8005\u8bf4\u662f […]<\/p>\n","protected":false},"author":1479,"featured_media":57033,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-104078","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\/104078","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\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=104078"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/104078\/revisions"}],"predecessor-version":[{"id":293008,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/104078\/revisions\/293008"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/57033"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=104078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=104078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=104078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}