{"id":506,"date":"2015-03-14T11:23:40","date_gmt":"2015-03-14T03:23:40","guid":{"rendered":"http:\/\/www.datarelab.com\/blog\/?p=506"},"modified":"2015-03-14T11:23:40","modified_gmt":"2015-03-14T03:23:40","slug":"ssh%e5%8f%8d%e5%90%91%e8%bf%9e%e6%8e%a5%e5%92%8c%e7%ae%80%e5%8d%95%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.datarelab.com\/blog\/Technical_literature\/506.html","title":{"rendered":"ssh\u53cd\u5411\u8fde\u63a5\u548c\u7b80\u5355\u5b9e\u73b0"},"content":{"rendered":"<p>SSH\u53cd\u5411\u8fde\u63a5\u7684\u4f7f\u7528<\/p>\n<p><strong>1\u3001\u4ec0\u4e48\u662f\u53cd\u5411\u8fde\u63a5\uff1f<\/strong><br \/>\n\u53cd\u5411\u8fde\u63a5\u662f\u6307\u4e3b\u673aA\uff08\u53d7\u63a7\u7aef\uff09\u4e3b\u52a8\u8fde\u63a5\u4e3b\u673aB\uff08\u63a7\u5236\u7aef\uff09\uff0c\u5728\u4e3b\u673aA\u548c\u4e3b\u673aB\u4e4b\u95f4\u5efa\u7acb\u4e00\u4e2a\u8fdc\u7a0b\u8fde\u63a5\uff0c\u901a\u8fc7\u8fd9\u4e2a\u8fde<br \/>\n\u63a5\u4e3b\u673aB\u53ef\u4ee5\u4e3b\u52a8\u7684\u5411\u4e3b\u673aA\u53d1\u9001\u4e00\u4e9b\u8bf7\u6c42\u3002<\/p>\n<p><strong>2\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u4e3b\u673aA\u4e3b\u52a8\u53bb\u8fde\u63a5\u4e3b\u673aB\u5462\uff1f<\/strong><br \/>\n\u8fd9\u662f\u56e0\u4e3a\u4e3b\u673aA\u5728\u5c40\u57df\u7f51\u5185\uff0c\u5982\u679c\u6ca1\u6709\u5bf9\u4e3b\u673aA\u8fdb\u884c\u7aef\u53e3\u6620\u5c04\uff0c\u5bf9\u4e8e\u4e3b\u673aB\u6765\u8bf4\u4e3b\u673aA\u662f\u4e0d\u53ef\u89c1\u7684\uff0c\u5982\u679c\u5728\u4e3b\u673aB\u8fd9<br \/>\n\u8fb9\u5411\u4e3b\u673aA\u53d1\u9001\u8fde\u63a5\u8bf7\u6c42\uff0c\u8fd9\u4e2a\u8bf7\u6c42\u662f\u4e0d\u53ef\u8fbe\u7684\u3002\u800c\u4e3b\u673aB\u6709\u81ea\u5df1\u72ec\u7acb\u7684IP\uff0c\u5bf9\u4e8e\u4e3b\u673aA\u6765\u8bf4\u662f\u53ef\u89c1\u7684\uff0c\u53ef\u4ee5\u76f4\u63a5\u5411<br \/>\n\u4e3b\u673aB\u8bf7\u6c42\u8fde\u63a5\u3002<\/p>\n<p><strong>3\u3001SSH\u53cd\u5411\u8fde\u63a5\u7684\u8fc7\u7a0b<\/strong><br \/>\n\u65b9\u6cd5\u5c31\u662f\u4e3b\u673aA\u4e3b\u52a8\u53bb\u8fde\u63a5\u4e3b\u673aB\uff0c\u4e3b\u673aB\u54cd\u5e94\u4e3b\u673aA\u7684\u8fde\u63a5\u8bf7\u6c42\uff0c\u5b83\u4eec\u4e4b\u95f4\u5c31\u5efa\u7acb\u4e86\u4e00\u4e2a\u8fdc\u7a0b\u8fde\u63a5\u3002\u7136\u540e\u4e3b\u673aB\u5728<br \/>\n\u672c\u5730\u518d\u521b\u5efa\u4e00\u4e2a\u672c\u5730\u8fde\u63a5\uff0c\u91cd\u5b9a\u5411\u5230\u4e3b\u673aA\u548c\u4e3b\u673aB\u521a\u624d\u5efa\u7acb\u7684\u8fdc\u7a0b\u8fde\u63a5\u4e0a\uff0c\u4e4b\u540e\u5bf9\u8fd9\u4e2a\u672c\u5730\u8fde\u63a5\u7684\u64cd\u4f5c\u90fd\u4f1a\u53cd\u9988\u5230<br \/>\n\u8fdc\u7a0b\u8fde\u63a5\u4e0a\u53bb\u3002\u6574\u4e2a\u8fc7\u7a0b\u7c7b\u4f3c\u4e8e\u6587\u4ef6\u7684DUP\uff0c\u8fd9\u5c31\u5728\u4e3b\u673aA\u548c\u4e3b\u673aB\u4e4b\u95f4\u5efa\u7acb\u4e86\u8fde\u63a5\u901a\u9053\uff0c\u6b64\u65f6\u5bf9\u4e8e\u4e3b\u673aB\u6765\u8bf4\uff0c\u4e3b<br \/>\n\u673aA\u5df2\u7ecf\u662f\u53ef\u89c1\u4e86\u3002<\/p>\n<p>\u8fde\u63a5\u6d41\u7a0b\u5982\u4e0b\uff1a<br \/>\n3.1\u3001\u4e3b\u673aA ssh\u5ba2\u6237\u7aef\u5411\u4e3b\u673aB sshd\u670d\u52a1\u7aef\u53d1\u9001\u8bf7\u6c42\uff0c\u5efa\u7acb\u8fdc\u7a0b\u8fde\u63a5\u3002<br \/>\n3.2\u3001\u4e3b\u673aB sshd\u670d\u52a1\u7aef\u521b\u5efa\u672c\u5730\u8fde\u63a5\u5f88\u8fdc\u7a0b\u8fde\u63a5\u7684\u6620\u5c04\uff08\u53cd\u5411\u8fde\u63a5\u901a\u9053\uff09\u3002<br \/>\n3.3\u3001\u4e3b\u673aB ssh\u5ba2\u6237\u7aef\u5411\u4e3b\u673aB sshd\u670d\u52a1\u7aef\u7684\u8fde\u63a5\u901a\u9053\u53d1\u9001\u8bf7\u6c42\uff0c \u5efa\u7acb\u4e3b\u673aB ssh\u548c\u4e3b\u673aA sshd\u7684\u8fde\u63a5\u3002<\/p>\n<p>\u5b8c\u6210\u8fde\u63a5\u540e\uff0c\u4e3b\u673aA\u5bf9\u4e8e\u4e3b\u673aB\u53ef\u89c1\u7684\u5f62\u5f0f\u5c31\u662f\u5b58\u5728\u4e8e\u4e3b\u673aB\u7684\u90a3\u4e2a\u672c\u5730\u8fde\u63a5\u3002<\/p>\n<p><strong>4\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u5728\u4e3b\u673aB\u5bf9\u8fdc\u7a0b\u8fde\u63a5\u6620\u5c04\u4e00\u4e2a\u672c\u5730\u8fde\u63a5\uff1f<\/strong><br \/>\n\u53cd\u5411\u8fde\u63a5\u5c31\u662fCS\u67b6\u6784\uff0c\u4e0d\u8fc7\u662f\u53d7\u63a7\u7aef\u4e3b\u52a8\u5411\u63a7\u5236\u7aef\u8bf7\u6c42\u8fde\u63a5\uff0c\u8ba9\u5b83\u4eec\u4e4b\u95f4\u7684\u8fde\u63a5\u5efa\u7acb\u3002\u4f20\u7edf\u7684CS\u65b9\u5f0f\u662f\u53ef\u4ee5\u89e3\u51b3<br \/>\n\u4e3b\u673aA\u548c\u4e3b\u673aB\u4e4b\u95f4\u7684\u8fde\u63a5\u95ee\u9898\uff0c\u4f46\u662f\u90a3\u6837\u4e3b\u673aA\u548c\u4e3b\u673aB\u7684\u8fde\u63a5\u65b9\u5f0f\u5e76\u4e0d\u7075\u6d3b\uff0c\u4e24\u8005\u4e4b\u95f4\u80fd\u505a\u7684\u4e8b\u60c5\uff0c\u53ea\u80fd\u662fCS\u4e4b\u9645<br \/>\n\u534f\u8bae\u89c4\u5b9a\u7684\u4e8b\u60c5\u3002\u5728\u4e3b\u673aB\u4e0a\u5efa\u7acb\u4e86\u4e3b\u673aA\u7684\u8fde\u63a5\u6620\u5c04\u540e\uff0c \u5bf9\u4e8e\u4e3b\u673aB\u6765\u8bf4\u4e3b\u673aA\u5df2\u7ecf\u4e0d\u662f\u5c40\u57df\u7f51\u5185\u90a3\u53f0\u4e0d\u53ef\u89c1\u7684\u4e3b<br \/>\n\u673a\uff0c\u4e3b\u673aA\u5df2\u7ecf\u662f\u5b58\u5728\u4e3b\u673aB\u7684\u4e00\u53f0\u53ef\u89c1\u4e3b\u673a\uff0c\u8fd9\u6837\u5c31\u6d88\u9664\u4e86\u5c40\u57df\u7f51\u548c\u5e7f\u57df\u7f51\u7684\u963b\u788d\u3002 \u4e3b\u673aA\u548c\u4e3b\u673aB\u4e4b\u95f4\u5efa\u7acb\u7684\u90a3<br \/>\n\u4e2a\u8fdc\u7a0b\u8fde\u63a5\u5c31\u662f\u4e3b\u673aA\u548c\u4e3b\u673aB\u7684\u901a\u9053\uff0d\u201c\u7f51\u7ebf\u201d\u3002<\/p>\n<p><strong>5\u3001SSH\u53cd\u5411\u8fde\u63a5\u7684\u4f7f\u7528<\/strong><br \/>\n\u8981\u5efa\u7acb\u53cd\u5411\u8fde\u63a5\uff0c\u9996\u5148\u5728\u4e3b\u673aA\u4e0a\u8fd0\u884c\uff1a<\/p>\n<p><span style=\"color: #ff0000;\">ssh -f -N -R 10000:localhost:22 lyb@3322.org<\/span><\/p>\n<p>10000\u662f\u4e3b\u673aB\u4e0a\u7684\u672c\u5730\u8fde\u63a5\u7aef\u53e3\uff0c 22\u662f\u4e3b\u673aB\u4e0a\u8fdc\u7a0b\u8fde\u63a5\u7684\u90a3\u4e2a\u7aef\u53e3\uff0c lyb@3322.org\u662f\u4e3b\u673aB\u7684\u5730\u5740<br \/>\n\u8fde\u63a5\u4e0a\u540e\uff0c\u4f1a\u9700\u8981\u8f93\u5165\u5bc6\u7801\u3002\u8fde\u63a5\u6210\u529f\u540e\uff0cSSH\u53cd\u5411\u8fde\u63a5\u5c31\u5efa\u7acb\u8d77\u6765\u4e86\u3002\u8981\u8fde\u63a5\u5230\u4e3b\u673aA\uff0c\u5728\u4e3b\u673aB\u4e0a\u8fd0\u884c\uff1a<\/p>\n<p><span style=\"color: #ff0000;\">ssh lyb@localhost -p 10000<\/span><\/p>\n<p>\u5373\u53ef\u3002<\/p>\n<p>\u4f7f\u7528\u7684\u8fc7\u7a0b\u4e2d\u78b0\u5230\u4e00\u4e2a\u95ee\u9898\uff0c \u5c31\u662f\u5728\u4e3b\u673aA\u4e0a\u53d1\u8d77\u8bf7\u6c42\u7684\u65f6\u5019\uff0c \u9700\u8981\u8f93\u5165\u5bc6\u7801\u3002 \u5982\u679c\u6211\u5728\u5bb6\u91cc\uff0c \u4e0d\u53ef\u80fd\u8dd1\u5230\u516c\u53f8\u4e86\u53bb\u8f93\u5165\u5bc6\u7801\u3002\u4e8e\u662f\u7528ssh public key\u7684\u65b9\u6cd5\u548c\u5199\u4e00\u4e2a\u811a\u672c\u6765\u89e3\u51b3\u3002\u811a\u672c\u5982\u4e0b\uff1a<\/p>\n<p><span style=\"color: #ff0000;\">#!\/bin\/bash<\/span><br \/>\n<span style=\"color: #ff0000;\">while true;do<\/span><br \/>\n<span style=\"color: #ff0000;\">RET=`ps ax | grep \"ssh -f -N -R 10000:localhost:22\" | grep -v \"grep\"`<\/span><br \/>\n<span style=\"color: #ff0000;\">if [ \"$RET\" = \"\" ]; then<\/span><br \/>\n<span style=\"color: #ff0000;\">echo \"restart ssh server\"<\/span><br \/>\n<span style=\"color: #ff0000;\">ssh -f -N -R 10000:localhost:22 lyb@hahalee.3322.org<\/span><br \/>\n<span style=\"color: #ff0000;\">fi<\/span><br \/>\n<span style=\"color: #ff0000;\">sleep 10<\/span><br \/>\n<span style=\"color: #ff0000;\">done<\/span><\/p>\n<p>\u811a\u672c\u7684\u4f5c\u7528\u5c31\u662f\u76d1\u63a7\u53cd\u5411\u8fde\u63a5\u7684\u670d\u52a1\uff0c \u5728\u88ab\u5f02\u5e38\u4e2d\u65ad\u7684\u65f6\u5019\u91cd\u542f\uff0c \u4f7f\u7528\u4e86SSH\u516c\u94a5\u540e\uff0c \u4e5f\u4e0d\u5fc5\u8dd1\u5230\u516c\u53f8\u8f93\u5165\u5bc6\u7801\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SSH\u53cd\u5411\u8fde\u63a5\u7684\u4f7f\u7528 1\u3001\u4ec0\u4e48\u662f\u53cd\u5411\u8fde\u63a5\uff1f \u53cd\u5411\u8fde\u63a5\u662f\u6307\u4e3b\u673aA\uff08\u53d7\u63a7\u7aef\uff09\u4e3b\u52a8\u8fde\u63a5\u4e3b\u673aB\uff08\u63a7\u5236\u7aef\uff09\uff0c\u5728\u4e3b\u673aA\u548c\u4e3b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-506","post","type-post","status-publish","format-standard","hentry","category-Technical_literature"],"views":1256,"_links":{"self":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/506","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/comments?post=506"}],"version-history":[{"count":0,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/506\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/media?parent=506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/categories?post=506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/tags?post=506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}