{"id":116,"date":"2023-06-26T11:24:35","date_gmt":"2023-06-26T03:24:35","guid":{"rendered":"https:\/\/www.book2022.top\/?p=116"},"modified":"2023-06-26T11:24:35","modified_gmt":"2023-06-26T03:24:35","slug":"%e7%bb%99-vps-%e9%85%8d%e7%bd%ae-ssh-%e5%af%86%e9%92%a5%e5%85%8d%e5%af%86%e7%99%bb%e5%bd%95-2","status":"publish","type":"post","link":"https:\/\/txt.book2020.top\/?p=116","title":{"rendered":"\u7ed9 VPS \u914d\u7f6e SSH \u5bc6\u94a5\u514d\u5bc6\u767b\u5f55"},"content":{"rendered":"\n<p><strong>\u514d\u5bc6\u767b\u5f55\u539f\u7406<\/strong><\/p>\n\n\n\n<p>\u5229\u7528\u5bc6\u94a5\u751f\u6210\u5668\u5236\u4f5c\u4e00\u5bf9\u5bc6\u94a5 \u2014\u2014 \u516c\u94a5\u548c\u79c1\u94a5\u3002\u5c06\u516c\u94a5\u6dfb\u52a0\u5230\u670d\u52a1\u5668\u7684\u67d0\u4e2a\u8d26\u6237\u4e0a\uff0c\u7136\u540e\u5728\u5ba2\u6237\u7aef\u5229\u7528\u79c1\u94a5\u5373\u53ef\u5b8c\u6210\u8ba4\u8bc1\u5e76\u767b\u5f55\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u6ca1\u6709\u79c1\u94a5\uff0c\u4efb\u4f55\u4eba\u90fd\u65e0\u6cd5\u901a\u8fc7 SSH \u66b4\u529b\u7834\u89e3\u4f60\u7684\u5bc6\u7801\u6765\u8fdc\u7a0b\u767b\u5f55\u5230\u7cfb\u7edf\u3002\u6b64\u5916\uff0c\u5982\u679c\u5c06\u516c\u94a5\u590d\u5236\u5230\u5176\u4ed6\u8d26\u6237\u751a\u81f3\u4e3b\u673a\uff0c\u5229\u7528\u79c1\u94a5\u4e5f\u53ef\u4ee5\u767b\u5f55\u3002<\/p>\n\n\n\n<p><strong>\u751f\u6210 SSH \u5bc6\u94a5\u5bf9<\/strong><\/p>\n\n\n\n<p>\u751f\u6210\u5bc6\u94a5\u53ef\u4ee5\u5728\u8fdc\u7aef VPS \u4e0a\uff0c\u4e5f\u53ef\u4ee5\u5728\u672c\u5730\u7ec8\u7aef\u4e0a\u8fdb\u884c\u64cd\u4f5c\uff0c\u65b9\u6cd5\u90fd\u662f\u7c7b\u4f3c\u7684\u3002<\/p>\n\n\n\n<p>\u8f93\u5165\u547d\u4ee4&nbsp;<code>ssh-keygen<\/code>&nbsp;\u7136\u540e\u6309 4 \u6b21 En\u00adter \u952e\u5c31\u884c\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark>root@p3ter:~# ssh-keygen  # \u8f93\u5165\u547d\u4ee4\uff0c\u6309 Enter \u952e\nGenerating public\/private rsa key pair.\nEnter file in which to save the key (\/root\/.ssh\/id_rsa):   #  \u4fdd\u5b58\u4f4d\u7f6e\uff0c\u9ed8\u8ba4\u5c31\u884c\uff0c\u6309 Enter \u952e\nEnter passphrase (empty for no passphrase):   # \u8f93\u5165\u5bc6\u94a5\u5bc6\u7801\uff0c\u6309 Enter \u952e\u3002\u586b\u5199\u540e\u6bcf\u6b21\u90fd\u4f1a\u8981\u6c42\u8f93\u5165\u5bc6\u7801\uff0c\u7559\u7a7a\u5219\u5b9e\u73b0\u65e0\u5bc6\u7801\u767b\u5f55\u3002\nEnter same passphrase again:   # \u518d\u6b21\u8f93\u5165\u5bc6\u94a5\u5bc6\u7801\uff0c\u6309 Enter \u952e\nYour identification has been saved in \/root\/.ssh\/id_rsa.\nYour public key has been saved in \/root\/.ssh\/id_rsa.pub.\nThe key fingerprint is:\nSHA256:GYT9YqBV4gDIgzTYEWFs3oGZjp8FWXArBObfhPlPzIk root@p3ter\nThe key's randomart image is:\n+---&#91;RSA 2048]----+\n|*OO%+ .+o        |\n|*=@.+++o.        |\n| *o=.=....       |\n|. +.B + +o.      |\n| . + E *S.       |\n|  o   o          |\n|       .         |\n|                 |\n|                 |\n+----&#91;SHA256]-----+<\/mark><\/code><\/pre>\n\n\n\n<p>\u73b0\u5728\uff0c\u5728\u5f53\u524d\u7528\u6237\u7684\u6839\u76ee\u5f55\u4e2d\u751f\u6210\u4e86\u4e00\u4e2a&nbsp;<code>.ssh<\/code>&nbsp;\u7684\u9690\u85cf\u76ee\u5f55\uff0c\u5185\u542b\u4e24\u4e2a\u5bc6\u94a5\u6587\u4ef6\u3002<code>id_rsa<\/code>&nbsp;\u4e3a\u79c1\u94a5\uff0c<code>id_rsa.pub<\/code>&nbsp;\u4e3a\u516c\u94a5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b89\u88c5\u516c\u94a5<\/h2>\n\n\n\n<p><strong>\u5bc6\u94a5\u5728\u8fdc\u7aef<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u751f\u6210\u5bc6\u94a5\u7684\u64cd\u4f5c\u662f\u5728\u5f53\u524d\u8981\u6dfb\u52a0\u7684 VPS \u4e0a\u8fdb\u884c\u7684\uff0c\u6ce8\u610f\u4fdd\u5b58\u79c1\u94a5&nbsp;<code>id_rsa<\/code>&nbsp;\u6587\u4ef6\u5230\u672c\u5730\uff0c\u7136\u540e\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u516c\u94a5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd .ssh\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>cat id_rsa.pub &gt;&gt; authorized_keys # \u5c06\u516c\u94a5\u5199\u5165\u5230 authorized_keys \u6587\u4ef6<\/code><\/pre>\n\n\n\n<p><strong>\u5bc6\u94a5\u5728\u672c\u5730<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u751f\u6210\u5bc6\u94a5\u7684\u64cd\u4f5c\u662f\u5728\u672c\u5730\u7ec8\u7aef\u4e0a\u8fdb\u884c\u7684\uff0c\u90a3\u4e48\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5c06\u516c\u94a5\u4e0a\u4f20\u5230 VPS\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh-copy-id user@remote -p port<\/code><\/pre>\n\n\n\n<p><strong><mark><code>user<\/code>&nbsp;\u4e3a\u7528\u6237\u540d\uff0c<code>remote<\/code>&nbsp;\u4e3aIP\u5730\u5740\uff0c<code>port<\/code>\u4e3a\u7aef\u53e3\u53f7\u3002<\/mark><\/strong><\/p>\n\n\n\n<p>\u5728\u6ca1\u6709&nbsp;<code>ssh-copy-id<\/code>&nbsp;\u7684\u60c5\u51b5\u4e0b\uff08\u6bd4\u5982\u5728 Win\u00addows \u4e0a\uff09, \u4e5f\u53ef\u4ee5\u7528\u547d\u4ee4\u6765\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh user@remote -p port 'mkdir -p .ssh &amp;&amp; cat &gt;&gt; .ssh\/authorized_keys' &lt; ~\/.ssh\/id_rsa.pub<\/code><\/pre>\n\n\n\n<p><mark>\u547d\u4ee4\u7684\u542b\u4e49\u662f\uff0c\u5728\u8fdc\u7aef\u65b0\u5efa&nbsp;<code>.ssh<\/code>&nbsp;\u6587\u4ef6\u5939\uff0c\u5e76\u628a\u672c\u5730\u7684&nbsp;<code>~\/.ssh\/id_rsa.pub<\/code>\uff08\u516c\u94a5\uff09\u8ffd\u52a0\u5230\u8fdc\u7aef\u7684&nbsp;<code>.ssh\/authorized_keys<\/code>&nbsp;\u4e2d\u3002<\/mark><\/p>\n\n\n\n<p>\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u624b\u52a8\u8fdb\u884c\u64cd\u4f5c\uff0c\u5148\u590d\u5236\u516c\u94a5\uff0c\u518d\u767b\u5f55 VPS \uff0c\u7c98\u8d34\u5230&nbsp;<code>.ssh\/authorized_keys<\/code>&nbsp;\u4e2d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4fee\u6539\u6743\u9650<\/h2>\n\n\n\n<p>\u4e3a\u4e86\u786e\u4fdd\u8fde\u63a5\u6210\u529f\uff0c\u52a1\u5fc5\u4fee\u6539\u6587\u4ef6\u6743\u9650\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod 600 ~\/.ssh\/authorized_keys<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod 700 ~\/.ssh<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4fee\u6539 sshd \u914d\u7f6e\u6587\u4ef6<\/h2>\n\n\n\n<p><strong>\u5f00\u542f\u5bc6\u94a5\u767b\u5f55\u9009\u9879<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7f16\u8f91&nbsp;<code>\/etc\/ssh\/sshd_config<\/code>&nbsp;\u6587\u4ef6\u627e\u5230\u4ee5\u4e0b\u53c2\u6570\u8fdb\u884c\u66f4\u6539\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>PubkeyAuthentication yes<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u91cd\u542f sshd \u670d\u52a1<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>service sshd restart<\/code><\/pre>\n\n\n\n<p><strong>\u7981\u7528\u5bc6\u7801\u767b\u5f55<\/strong><\/p>\n\n\n\n<p>\u5728\u4f60\u786e\u8ba4\u5bc6\u94a5\u80fd\u6210\u529f\u767b\u5f55\u540e\uff0c\u5982\u679c\u9700\u8981\u7981\u7528\u5bc6\u7801\u767b\u5f55\uff0c\u8bf7\u66f4\u6539\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PasswordAuthentication no<\/code><\/pre>\n\n\n\n<p><strong>\u91cd\u542f sshd \u670d\u52a1<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>service sshd restart<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u53c2\u8003<\/h2>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/p3terx.com\/go\/aHR0cHM6Ly96aHVhbmxhbi56aGlodS5jb20vcC8yMTk5OTc3OA\" target=\"_blank\">SSH \u57fa\u672c\u7528\u6cd5<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u514d\u5bc6\u767b\u5f55\u539f\u7406 \u5229\u7528\u5bc6\u94a5\u751f\u6210\u5668\u5236\u4f5c\u4e00\u5bf9\u5bc6\u94a5 \u2014\u2014 \u516c\u94a5\u548c\u79c1\u94a5\u3002\u5c06\u516c\u94a5\u6dfb\u52a0\u5230\u670d\u52a1\u5668\u7684\u67d0\u4e2a\u8d26\u6237\u4e0a\uff0c\u7136\u540e\u5728\u5ba2\u6237\u7aef\u5229\u7528\u79c1&#8230;<\/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-116","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/txt.book2020.top\/index.php?rest_route=\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/txt.book2020.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/txt.book2020.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/txt.book2020.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/txt.book2020.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=116"}],"version-history":[{"count":0,"href":"https:\/\/txt.book2020.top\/index.php?rest_route=\/wp\/v2\/posts\/116\/revisions"}],"wp:attachment":[{"href":"https:\/\/txt.book2020.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/txt.book2020.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/txt.book2020.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}