{"id":110966,"date":"2018-08-05T08:46:36","date_gmt":"2018-08-05T00:46:36","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=110966"},"modified":"2018-07-30T08:47:44","modified_gmt":"2018-07-30T00:47:44","slug":"linux-sftp","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-sftp.html","title":{"rendered":"\u5982\u4f55\u5728Linux\u4e0b\u8fdb\u884cSFTP\u7528\u6237\u6743\u9650\u8bbe\u7f6e"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u3000\u4f60\u7684openssh-server\u7248\u672c\u81f3\u5c11\u5f97\u59314.8p1, \u56e0\u4e3a\u914d\u7f6e\u6743\u9650\u9700\u8981\u7248\u672c\u6dfb\u52a0\u7684\u65b0\u914d\u7f6e\u9879ChrootDirectory\u6765\u5b8c\u6210\u3002\u5982\u4f55\u67e5\u770b\u81ea\u5df1\u670d\u52a1\u5668\u4e0a\u7684ssh\u7248\u672c?\u5927\u5bb6\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u547d\u4ee4\uff1a$ ssh -V<\/span><\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5177\u4f53\u5b9e\u65bd\u6b65\u9aa4\uff1a<\/p>\n

1. \u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u7528\u6237\u7ec4\uff0c\u4e13\u95e8\u7528\u4e8esftp\u7528\u6237<\/strong><\/div>\n
$ groupadd sftpusers<\/pre>\n
2. \u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u7528\u6237test<\/strong><\/div>\n
$ useradd -s \/bin\/false -G sftpuser test<\/pre>\n

\u6ce8\u610f\u8fd9\u91cc\u6211\u4eec\u5c06test\u7528\u6237\u7684shell\u8bbe\u7f6e\u4e3a\/bin\/false\u4f7f\u4ed6\u6ca1\u6709\u767b\u9646shell\u7684\u6743\u9650<\/p>\n

3. \u7f16\u8f91 \/etc\/ssh\/sshd_config<\/strong><\/div>\n

\u627e\u5230Subsystem\u8fd9\u4e2a\u914d\u7f6e\u9879\uff0c\u5c06\u5176\u4fee\u6539\u4e3a<\/p>\n

Subsystem sftp internal-sftp<\/pre>\n

\u7136\u540e\u518d\u5230\u6587\u4ef6\u6700\u5c3e\u5904\u589e\u52a0\u914d\u7f6e\u8bbe\u5b9a\u5c5e\u4e8e\u7528\u6237\u7ec4sftpusers\u7684\u7528\u6237\u90fd\u53ea\u80fd\u8bbf\u95ee\u4ed6\u4eec\u81ea\u5df1\u7684home\u6587\u4ef6\u5939<\/p>\n

Match Group sftpusers\r\n\r\nChrootDirectory %h\r\n\r\nForceCommand internal-sftp\r\n\r\nAllowTcpForwarding no<\/pre>\n

\u4fdd\u5b58\u5e76\u5173\u95ed\u6587\u4ef6<\/p>\n

4. \u4fee\u6539test\u7528\u6237home\u6587\u4ef6\u5939\u7684\u6743\u9650\uff0c\u8ba9\u5176\u5c5e\u4e8eroot\u7528\u6237<\/strong><\/div>\n
chown root ~test<\/pre>\n
5. \u91cd\u542fsshd\u670d\u52a1<\/strong><\/div>\n
$ service sshd restart<\/pre>\n
6. \u6d4b\u8bd5\u7528\u6237\u8d26\u53f7<\/strong><\/div>\n
$ ssh test@localhost<\/pre>\n

\u8fde\u63a5\u4f1a\u88ab\u62d2\u7edd\u6216\u8005\u65e0\u6cd5\u767b\u9646<\/p>\n

$ sftp tesst@localhost<\/pre>\n

\u767b\u9646\u540e\u4f60\u4f1a\u53d1\u73b0\u4f60\u7684\u8d26\u53f7\u65e0\u6cd5\u5207\u6362\u5230\u9664\u81ea\u5df1home\u76ee\u5f55\u4e4b\u5916\u7684\u5730\u65b9\u7684<\/p>\n

\u5e38\u89c1\u95ee\u9898\uff1a<\/p>\n

\u5982\u679c\u4f60\u94fe\u63a5\u670d\u52a1\u5668\u7684\u65f6\u5019\u51fa\u73b0\u4e0b\u9762\u7684\u63d0\u793a\uff1a<\/p>\n

Write failed: Broken pipe\r\n\r\nCouldn't read packet: Connection reset by peer<\/pre>\n

\u8fd9\u4e2a\u95ee\u9898\u7684\u539f\u56e0\u662fChrootDirectory\u7684\u6743\u9650\u95ee\u9898\uff0c\u4f60\u8bbe\u5b9a\u7684\u76ee\u5f55\u5fc5\u987b\u662froot\u7528\u6237\u6240\u6709\uff0c\u5426\u5219\u5c31\u4f1a\u51fa\u73b0\u95ee\u9898\u3002\u6240\u4ee5\u8bf7\u786e\u4fddsftp\u7528\u6237\u6839\u76ee\u5f55\u7684\u6240\u6709\u4eba\u662froot, \u6743\u9650\u662f 750 \u6216\u8005 755\u3002<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.jsgho.net\/help\/fwq\/30399.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1a https:\/\/lrxjmw.cn\/linux-sftp.html<\/a>\u7f16\u8f91\uff1a\u90dd\u5927\u53d1\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb \u3000\u4f60\u7684openssh-server\u7248\u672c\u81f3\u5c11\u5f97\u59314.8p1, \u56e0\u4e3a\u914d\u7f6e\u6743\u9650\u9700\u8981\u7248\u672c\u6dfb\u52a0\u7684\u65b0\u914d\u7f6e\u9879Chroo […]<\/p>\n","protected":false},"author":63,"featured_media":113924,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-110966","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\/110966","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\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=110966"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/110966\/revisions"}],"predecessor-version":[{"id":113949,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/110966\/revisions\/113949"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/113924"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=110966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=110966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=110966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}