{"id":209,"date":"2024-04-21T22:15:32","date_gmt":"2024-04-21T14:15:32","guid":{"rendered":"http:\/\/xiyu12.top\/?p=209"},"modified":"2024-04-21T22:15:32","modified_gmt":"2024-04-21T14:15:32","slug":"ssh-%e5%b1%95%e5%bc%80","status":"publish","type":"post","link":"http:\/\/www.xiyu12.top\/?p=209","title":{"rendered":"ssh \u5c55\u5f00"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">SSH\uff08Secure Shell\uff09\u662f\u4e00\u79cd\u7f51\u7edc\u534f\u8bae\uff0c\u7528\u4e8e\u52a0\u5bc6\u65b9\u5f0f\u8fdc\u7a0b\u767b\u5f55\u548c\u5176\u4ed6\u7f51\u7edc\u670d\u52a1\u3002\u4f7f\u7528SSH\u53ef\u4ee5\u5b89\u5168\u5730\u5728\u4e0d\u5b89\u5168\u7684\u7f51\u7edc\u4e0a\u63d0\u4f9b\u5b89\u5168\u7684\u6570\u636e\u4f20\u8f93\u901a\u9053\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684SSH\u547d\u4ee4\u53ca\u5176\u6267\u884c\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u767b\u5f55\u8fdc\u7a0b\u670d\u52a1\u5668<\/strong>\uff1a<code>ssh username@hostname<\/code>\u8fd9\u91cc\u7684<code>username<\/code>\u662f\u4f60\u7684\u8fdc\u7a0b\u670d\u52a1\u5668\u7528\u6237\u540d\uff0c<code>hostname<\/code>\u662f\u8fdc\u7a0b\u670d\u52a1\u5668\u7684IP\u5730\u5740\u6216\u4e3b\u673a\u540d\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u7279\u5b9a\u7aef\u53e3\u767b\u5f55<\/strong>\uff1a<code>ssh -p port_number username@hostname<\/code>\u5982\u679c\u8fdc\u7a0b\u670d\u52a1\u5668\u76d1\u542c\u7684\u4e0d\u662fSSH\u9ed8\u8ba4\u768422\u7aef\u53e3\uff0c\u53ef\u4ee5\u901a\u8fc7<code>-p<\/code>\u9009\u9879\u6307\u5b9a\u7aef\u53e3\u53f7\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u79c1\u94a5\u6587\u4ef6\u767b\u5f55<\/strong>\uff1a<code>ssh -i \/path\/to\/private_key username@hostname<\/code>\u5f53\u8fdc\u7a0b\u670d\u52a1\u5668\u914d\u7f6e\u4e3a\u4ec5\u63a5\u53d7\u57fa\u4e8e\u5bc6\u94a5\u7684\u8ba4\u8bc1\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>-i<\/code>\u9009\u9879\u6307\u5b9a\u79c1\u94a5\u6587\u4ef6\u7684\u8def\u5f84\u3002<\/li>\n\n\n\n<li><strong>\u6267\u884c\u8fdc\u7a0b\u547d\u4ee4<\/strong>\uff1a<code>ssh username@hostname 'command'<\/code>\u5c06<code>command<\/code>\u66ff\u6362\u4e3a\u4f60\u60f3\u5728\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u6267\u884c\u7684\u547d\u4ee4\u3002<\/li>\n\n\n\n<li><strong>\u590d\u5236\u6587\u4ef6\u5230\u8fdc\u7a0b\u670d\u52a1\u5668<\/strong>\uff08\u4f7f\u7528SCP\u547d\u4ee4\uff09\uff1a<code>scp \/path\/to\/local_file username@hostname:\/path\/to\/remote_file<\/code>\u8be5\u547d\u4ee4\u5c06\u672c\u5730\u8def\u5f84<code>\/path\/to\/local_file<\/code>\u7684\u6587\u4ef6\u590d\u5236\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\u7684<code>\/path\/to\/remote_file<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u590d\u5236\u6587\u4ef6\u4ece\u8fdc\u7a0b\u670d\u52a1\u5668<\/strong>\uff1a<code>scp username@hostname:\/path\/to\/remote_file \/path\/to\/local_file<\/code>\u4e0e\u4e0a\u4e00\u6761\u547d\u4ee4\u76f8\u53cd\uff0c\u8fd9\u6761\u547d\u4ee4\u7528\u4e8e\u5c06\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u7684\u6587\u4ef6\u590d\u5236\u5230\u672c\u5730\u3002<\/li>\n\n\n\n<li><strong>\u4fdd\u6301\u8fde\u63a5\u6d3b\u52a8<\/strong>\uff1a<code>ssh -o ServerAliveInterval=60 username@hostname<\/code>\u4f7f\u7528<code>-o ServerAliveInterval=60<\/code>\u53ef\u4ee5\u6bcf\u969460\u79d2\u5411\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e2a\u7a7a\u5305\u4ee5\u4fdd\u6301\u8fde\u63a5\u6d3b\u8dc3\uff0c\u907f\u514d\u56e0\u7f51\u7edc\u95ee\u9898\u5bfc\u81f4\u8fde\u63a5\u8d85\u65f6\u3002<\/li>\n\n\n\n<li><strong>\u96a7\u9053\u8fde\u63a5<\/strong>\uff08\u7aef\u53e3\u8f6c\u53d1\uff09\uff1a<code>ssh -L local_port:localhost:remote_port username@hostname<\/code>\u8fd9\u4f1a\u5728\u672c\u5730\u673a\u5668\u4e0a\u521b\u5efa\u4e00\u4e2a\u7aef\u53e3<code>local_port<\/code>\uff0c\u5b83\u8f6c\u53d1\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u7684<code>remote_port<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u9000\u51faSSH\u4f1a\u8bdd<\/strong>\uff1a<code>exit<\/code>\u6216\u8005\u4f7f\u7528\u7b80\u5199\uff1a<code>quit<\/code>\u5728SSH\u4f1a\u8bdd\u4e2d\u8f93\u5165\u8fd9\u4e9b\u547d\u4ee4\u5c06\u7ed3\u675f\u5f53\u524d\u7684\u8fdc\u7a0b\u4f1a\u8bdd\u3002<\/li>\n\n\n\n<li><strong>\u67e5\u770b\u8fdc\u7a0b\u670d\u52a1\u5668\u7684SSH\u670d\u52a1\u72b6\u6001<\/strong>\uff1a<code>sudo service ssh status<\/code>\u6216\u8005\u4f7f\u7528systemctl\uff08\u5728\u57fa\u4e8esystemd\u7684\u7cfb\u7edf\u4e0a\uff09\uff1a<code>sudo systemctl status sshd<\/code><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>SSH\uff08Secure Shell\uff09\u662f\u4e00\u79cd\u7f51\u7edc\u534f\u8bae\uff0c\u7528\u4e8e\u52a0\u5bc6\u65b9\u5f0f\u8fdc\u7a0b\u767b\u5f55\u548c\u5176\u4ed6\u7f51\u7edc\u670d\u52a1\u3002\u4f7f\u7528SSH\u53ef\u4ee5\u5b89\u5168\u5730\u5728\u4e0d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":29,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[85],"class_list":["post-209","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-suibi","tag-ssh"],"_links":{"self":[{"href":"http:\/\/www.xiyu12.top\/index.php?rest_route=\/wp\/v2\/posts\/209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiyu12.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiyu12.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiyu12.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiyu12.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=209"}],"version-history":[{"count":0,"href":"http:\/\/www.xiyu12.top\/index.php?rest_route=\/wp\/v2\/posts\/209\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.xiyu12.top\/index.php?rest_route=\/wp\/v2\/media\/29"}],"wp:attachment":[{"href":"http:\/\/www.xiyu12.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiyu12.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiyu12.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}