{"id":836,"date":"2011-03-18T16:05:37","date_gmt":"2011-03-18T08:05:37","guid":{"rendered":"http:\/\/www.jpuyy.com\/blog\/?p=836"},"modified":"2021-09-02T11:58:01","modified_gmt":"2021-09-02T03:58:01","slug":"how-to-ssh-keygen","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=836","title":{"rendered":"ssh\u7684key\u7684\u751f\u6210"},"content":{"rendered":"<h2>\u751f\u6210\u5bc6\u94a5\u5bf9<\/h2>\n<p>\u4f7f\u7528ssh-keygen\u6765\u751f\u6210\u5bc6\u94a5\u5bf9<br \/>\n(\u5177\u4f53\u53c2\u6570\u8bf7\u53c2\u9605man ssh-keygen)<\/p>\n<pre>ssh-keygen -b 1024 -t rsa<\/pre>\n<p>Generating public\/private rsa key pair.<br \/>\nEnter file in which to save the key (\/root\/.ssh\/id_rsa):<br \/>\nEnter passphrase (empty for no passphrase):<br \/>\nEnter same passphrase again:<br \/>\nYour identification has been saved in \/root\/.ssh\/id_rsa.<br \/>\nYour public key has been saved in \/root\/.ssh\/id_rsa.pub.<br \/>\nThe key fingerprint is:<br \/>\n5c:81:74:f3:00:97:65:8a:09:ce:0e:43:ee:d7:66:72 root@debian<br \/>\nThe key&#8217;s randomart image is:<br \/>\n+&#8211;[ RSA 1024]&#8212;-+<br \/>\n| . ..oo*oo |<br \/>\n| o o ..=.B |<br \/>\n| + o o o . |<br \/>\n| . + o . |<br \/>\n| . + E |<br \/>\n| . = |<br \/>\n| |<br \/>\n| |<br \/>\n| |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/p>\n<h2>\u65e0\u4ea4\u4e92\u751f\u6210\u5bc6\u94a5\u5bf9<\/h2>\n<pre>ssh-keygen -b 2048 -t rsa -f ~\/.ssh\/id_rsa -q -N \"\"<\/pre>\n<h2>\u5bc6\u94a5\u5206\u53d1<\/h2>\n<p>\u65b9\u6cd51\uff1a<\/p>\n<p>\u521a\u624d\u751f\u6210\u4e86\u4e00\u5bf9\u5bc6\u94a5\uff0c\u628a\u79c1\u94a5\u653e\u5728\u81ea\u5df1\u7684\u673a\u5668\u4e0a\u7684~\/.ssh\/\u76ee\u5f55\u4e0b\u5e76\u4fdd\u8bc1\u8bbf\u95ee\u6743\u9650\u662f\u201c-rw&#8212;&#8212;-\u201d(\u5373600)\u3002\u79c1\u94a5\u6c38\u8fdc\u4e0d\u8981\u7ed9\u522b\u4eba\u3002<\/p>\n<p>\u518d\u628a\u751f\u6210\u7684\u516c\u94a5\u653e\u5728\u8981\u8fde\u63a5\u7684\u8fdc\u7a0b\u4e3b\u673a\u7684~\/.ssh\/\u76ee\u5f55\u4e0b\u5e76\u6539\u540d\u4e3a<code>authorized_keys<\/code>,\u5e76\u4e14\u4fdd\u8bc1\u6587\u4ef6\u9664\u4e86\u5c5e\u4e3b\u5916\u6ca1\u6709\u88ab\u4eba\u4fee\u6539\u7684\u6743\u9650\u201c-rw&#8212;&#8212;-\u201d(\u5373600)\u3002\u516c\u94a5\u65e0\u9700\u4fdd\u5bc6<\/p>\n<p>\u65b9\u6cd52\uff1a<\/p>\n<p>linux\u5185\u7f6e\u4e86<code>ssh-copy-id<\/code>\u547d\u4ee4\uff0c\u76f4\u63a5\u4f7f\u7528<\/p>\n<pre>ssh-copy-id jpuyy@jpuyy.com<\/pre>\n<p>\u7136\u540e\u6309\u63d0\u793a\u8f93\u5165\u5bc6\u7801\u4e4b\u540e\uff0c\u6b64\u811a\u672c\u4f1a\u81ea\u52a8\u5c06\u516c\u94a5copy\u5230\u76ee\u6807\u673a\u5668\u7528\u6237\u76ee\u5f55\u4e0b\u7684<code>authorized_keys<\/code>\u4e2d\u5e76\u4fee\u6539\u6743\u9650\u3002\u5bf9\u4e8e\u4e00\u4e2akey\u7ba1\u7406\u5927\u6279\u91cf\u4e3b\u673a\u65f6\u81ea\u52a8\u5316\u5206\u53d1\u3002\u5176\u5b9e\u5c31\u662f\u65b9\u6cd51\u7684\u811a\u672c\u5b9e\u73b0\u3002<\/p>\n<p>\u5982\u679c\u76ee\u6807\u4e3b\u673assh\u7aef\u53e3\u4e0d\u662f22\uff0c\u516c\u94a5\u4e5f\u4e0d\u662fid_rsa.pub\uff0c\u53ef\u4ee5\u6307\u5b9a\u7aef\u53e3\u548c\u516c\u94a5<\/p>\n<pre>ssh-copy-id -i \/home\/secure.pub \"-p 3322 jpuyy@jpuyy.com\"<\/pre>\n<h2>\u6d4b\u8bd5<\/h2>\n<p>ssh,scp\u4f7f\u7528\u5bc6\u94a5\u767b\u9646(-i\u6307\u5b9a\u79c1\u94a5\u8def\u5f84)<\/p>\n<pre>ssh -i jpuyy-key jpuyy@jpuyy.com<\/pre>\n<pre>scp -i jpuyy-key filename jpuyy@jpuyy.com:\/home\/<\/pre>\n<h2>\u66f4\u6539key\u7684passphrase<\/h2>\n<p>\u4e0a\u9762\u5728\u751f\u6210\u5bc6\u94a5\u5bf9\u7684\u65f6\u5019\u4f1a\u63d0\u793a\u8f93\u5165\u5bc6\u94a5\uff0c\u9700\u8981\u66f4\u6539id_rsa\u6587\u4ef6\u7684\u5bc6\u7801\u65f6\uff0c\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u5373\u53ef\u66f4\u6539\u3002<\/p>\n<pre>ssh-keygen -f id_rsa -p<\/pre>\n<p>\u5224\u65ad\u4e00\u5bf9\u516c\u79c1\u94a5\u662f\u4e0d\u662f\u4e00\u5bf9<\/p>\n<pre>diff &lt;( ssh-keygen -y -e -f \"~\/.ssh\/id_rsa\" ) &lt;( ssh-keygen -y -e -f \"ec2.demo.pub\" )\r\n<\/pre>\n<p>\u5982\u679c diff \u6709\u8f93\u51fa\u5219\u4e0d\u662f\u4e00\u5bf9<\/p>\n<p>\u9a8c\u8bc1 cert \u662f\u4e0d\u662f\u5408\u6cd5<\/p>\n<pre>\r\nssh-keygen -L -f ~\/.ssh\/id_rsa-cert.pub\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u751f\u6210\u5bc6\u94a5\u5bf9 \u4f7f\u7528ssh-keygen\u6765\u751f\u6210\u5bc6\u94a5\u5bf9 (\u5177\u4f53\u53c2\u6570\u8bf7\u53c2\u9605man ssh-keygen) ssh-keygen -b 1024 -t rsa Generating public\/private rsa key pair. Enter file in which to save the key (\/root\/.ssh\/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in \/root\/.ssh\/id_rsa. Your public key has been saved in \/root\/.ssh\/id_rsa.pub. The key fingerprint is: 5c:81:74:f3:00:97:65:8a:09:ce:0e:43:ee:d7:66:72 root@debian The [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[23],"class_list":["post-836","post","type-post","status-publish","format-standard","hentry","category-linux","tag-summary"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/836","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=836"}],"version-history":[{"count":21,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/836\/revisions"}],"predecessor-version":[{"id":9367,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/836\/revisions\/9367"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}