{"id":55,"date":"2024-03-11T07:56:39","date_gmt":"2024-03-10T23:56:39","guid":{"rendered":"https:\/\/www.cutegameit.com\/linux\/?p=66"},"modified":"2025-08-29T15:17:34","modified_gmt":"2025-08-29T07:17:34","slug":"ssh-key-%e7%9a%84%e5%bb%ba%e7%ab%8b-pc","status":"publish","type":"post","link":"https:\/\/www.cutexyz.com\/edu\/linux2402\/?p=55","title":{"rendered":"ssh key \u7684\u5efa\u7acb ( PC )"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u9996\u5148\u5728 windows \u4e0a\u5efa\u7acb key<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># open the terminal in windows and type the command as below\n# \u5728 windows \u4e0a\u6253\u770b\u7d42\u7aef\u6a5f( Window \u9375 + R \u7136\u5f8c\u8f38\u5165 cmd ), \u7136\u5f8c\u8f38\u5165\u4ee5\u4e0b\u6307\u4ee4\nssh-keygen\n\n# \u63a5\u4e0b\u4f86\u7cfb\u7d71\u6703\u554f\u4f60\u4e00\u4e9b\u554f\u984c\n# \u554f\u984c 1: \u4f60\u7684 key \u64fa\u653e\u4f4d\u7f6e, \u5982\u679c\u4f60\u6709\u4e00\u500b\u4ee5\u4e0a\u7684 key \u8acb\u4f7f\u7528\u4e0d\u540c\u7684\u6a94\u6848\u540d\u7a31\n# \u554f\u984c 2: \u4f7f\u7528 key \u6642\u662f\u5426\u8981\u7528\u5bc6\u78bc\u4fdd\u8b77, \u5982\u679c\u4e0d\u8981\u5c31\u76f4\u63a5\u6309 enter\n# \u554f\u984c 3: \u540c\u4e0a, \u53ea\u662f\u8981\u4f60\u518d\u78ba\u5b9a\u4e00\u6b21\n\n# change to the .ssh directory\n# \u8b8a\u66f4\u76ee\u9304\u5230 .ssh \u4e0b\u9762\ncd .ssh\n\n# copy the content of the public key\n# \u8907\u88fd\u516c\u9470\u7684\u5167\u5bb9, \u4f7f\u7528 type \u6307\u4ee4\u53ef\u4ee5\u628a\u5167\u5bb9\u986f\u793a\u5728\u756b\u9762\u4e0a\n# \u8981\u5c07\u516c\u9470\u653e\u4e0a\u53bb server \u6709\u5f88\u591a\u7a2e\u65b9\u6cd5, \u9019\u908a\u50c5\u8aaa\u660e\u6700\u7c21\u55ae\u6613\u61c2\u7684\u8907\u88fd\u8cbc\u4e0a\u6b65\u9a5f\ntype id_rsa.pub<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u518d\u9023\u4e0a\u53bb Linux server \u8a2d\u5b9a<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># \u4ee5\u4e0b\u64cd\u4f5c\u662f\u5728\u5207\u63db\u70ba root \u7684\u5e33\u865f\u4e0b\u9032\u884c\n# \u53ef\u7528\u4e0b\u65b9\u6307\u4ee4\u5207\u63db\u70ba root\nsudo su -\n\n# add new account\n# \u65b0\u3f6a\u4e00\u500b\u5e33\u865f, \u5efa\u7acb\u7684\u7576\u4e0b\u6703\u554f\u4f60\u8981\u8a2d\u5b9a\u7684\u5bc6\u78bc\u8207\u5e33\u865f\u76f8\u95dc\u8cc7\u6599, \u53ef\u4e00\u5f8b\u4ee5 enter \u5e36\u904e \nadduser newcute\n\n# setup password, \u8acb\u5ffd\u7565\n# \u5efa\u7acb(\u4fee\u6539)\u5bc6\u78bc, \u53ef\u4ee5\u5ffd\u7565\npasswd newcute\n\n# assign the user group ( permission ), \u8acb\u5148\u5ffd\u7565\n# \u5c07 newcute \u52a0\u5165\u5230\u67d0\u4e00\u500b\u7fa4\u7d44, \u53ef\u4ee5\u5ffd\u7565\nusermod -a -G wheel newcute\n\n# change user to the new one, important\n# \u5c07\u5e33\u865f\u5207\u63db\u81f3 newcute\nsu newcute\n\n# change directory to the home\n# \u5207\u63db\u5230 newcute \u5e33\u865f\u7684\u5bb6\u76ee\u9304\ncd\n\n# make the require directory\n# \u5efa\u7acb\u6240\u9700\u8981\u7684\u76ee\u9304\nmkdir .ssh\n\n# change directory\n# \u5207\u63db\u5230\u8a72\u76ee\u9304\u4e4b\u4e0b\ncd .ssh\n\n# create an authorized_keys file:\n# \u5efa\u7acb\u6240\u9700\u6a94\u6848, \u6709\u5169\u7a2e\u65b9\u5f0f\u90fd\u53ef\u4ee5\u4f7f\u7528\nnano authorized_keys\n# or\nvi authorized_keys\n\n# paste the whole public key content\n# do this in the nano or vi UI\n# \u5c07\u525b\u525b\u5728 windows \u8907\u88fd\u7684\u5167\u5bb9\u8cbc\u5230 authorized_keys \u5167\u5bb9\u5f8c\u9032\u884c\u5b58\u6a94\u9000\u51fa\n\n# change the file permission for ssh\n# \u4fee\u6539\u76ee\u9304\u8207\u6a94\u6848\u7684\u6b0a\u9650\nchmod 700 ~\/.ssh\nchmod 600 ~\/.ssh\/authorized_keys\n\n# Edit configuration, \n# \u4fee\u6539 ssh \u7684\u670d\u52d9\u8a2d\u5b9a\u6a94\u6848\nvi \/etc\/ssh\/sshd_config\n\n# \u5c07\u4ee5\u4e0b\u5167\u5bb9\u4fee\u6539\u6253\u958b, \u8981\u6ce8\u610f\u662f\u5426\u6b63\u78ba\u70ba on \u8207 yes, \u5982\u679c\u662f\u88ab mark \u6389\u8a18\u5f97\u5c07\u524d\u9762\u7684 # \u7b26\u865f\u522a\u9664\n#################### \nPasswordAuthentication no\nPubkeyAuthentication yes\n\n# restart the ssh service\n# \u91cd\u65b0\u555f\u52d5 sshd \u670d\u52d9\nservice sshd restart\n\n# ==== \u4ee5\u4e0a\u5df2\u5b8c\u6210\u6240\u6709\u5de5\u4f5c, \u53ef\u4ee5\u9032\u884c\u6e2c\u8a66\u4e86 ====\n# NOW you can try it!!!!\n# &lt;&lt; \u65b9\u6cd5 1 &gt;&gt; \u6307\u5b9a key file\nssh -i keyname newcute@127.0.0.1\n# or\n# &lt;&lt; \u65b9\u6cd5 2 &gt;&gt; \u5982\u679c\u4f60\u53ea\u6709\u4e00\u7d44 key \u7684\u8a71\u5c31\u4e0d\u7528\u7279\u5225\u6307\u5b9a, \u4ed6\u6703\u63a1\u7528\u9810\u8a2d\u552f\u4e00\u7684\nssh newcute@127.0.0.1<\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u900f\u904e Windows \u7684 Powshell \u8a2d\u5b9a<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code># \u8a18\u5f97\u8981\u5c07 \u6a94\u6848\u4f4d\u7f6e\u8207 server \u76f8\u95dc\u8cc7\u8a0a\u505a\u9069\u7576\u7684\u8b8a\u66f4\u4ee5\u7b26\u5408\u4f60\u7684\u74b0\u5883\n\ncat ~\/.ssh\/id_rsa_cute301.pub | ssh -p2222 cute301@127.0.0.1 &quot;mkdir -p ~\/.ssh && touch ~\/.ssh\/authorized_keys && chmod -R go= ~\/.ssh && cat &gt;&gt; ~\/.ssh\/authorized_keys&quot;<\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u76f8\u95dc\u53c3\u8003\u8cc7\u6599<\/strong><br><a rel=\"noreferrer noopener\" href=\"https:\/\/www.footmark.com.tw\/news\/linux\/centos\/windows-ssh-nopassword-linux\/\" target=\"_blank\">https:\/\/www.footmark.com.tw\/news\/linux\/centos\/windows-ssh-nopassword-linux\/<\/a><br><br><strong>\u53e6\u4e00\u500b\u53c3\u8003\u8cc7\u6599<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-linziyou-dev-blog wp-block-embed-linziyou-dev-blog\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"bU0Sb2vYID\"><a href=\"https:\/\/linziyou.info\/2021\/09\/01\/%e5%a6%82%e4%bd%95%e7%94%a2%e7%94%9fssh-key\/\">\u5982\u4f55\u7522\u751fSSH Key<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"\u5982\u4f55\u7522\u751fSSH Key &#8212; LinZiyou Dev Blog\" src=\"https:\/\/linziyou.info\/2021\/09\/01\/%e5%a6%82%e4%bd%95%e7%94%a2%e7%94%9fssh-key\/embed\/#?secret=ypL2pi4CJJ#?secret=bU0Sb2vYID\" data-secret=\"bU0Sb2vYID\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><strong>chmod<\/strong> \u53c3\u8003\u8cc7\u6599<br><a href=\"https:\/\/weikaiwei.com\/linux\/chmod-commands\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/weikaiwei.com\/linux\/chmod-commands\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u5728 windows \u4e0a\u5efa\u7acb key \u518d\u9023\u4e0a\u53bb Linux server \u8a2d\u5b9a \u900f\u904e Windows \u7684 Powshell \u8a2d\u5b9a \u76f8\u95dc\u53c3\u8003\u8cc7\u6599https:\/\/www.footmark.com.tw\/news\/linux\/centos\/windows-ssh-nopassword-linux\/ \u53e6\u4e00\u500b\u53c3\u8003\u8cc7\u6599 chmod \u53c3\u8003\u8cc7\u6599https:\/\/weikaiwei.com\/linux\/chmod-commands\/<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"disable_featured_image":false,"footnotes":""},"categories":[7],"tags":[8,9],"class_list":["post-55","post","type-post","status-publish","format-standard","hentry","category-7","tag-ssh","tag-ssh-key"],"_links":{"self":[{"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=\/wp\/v2\/posts\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=55"}],"version-history":[{"count":7,"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":125,"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=\/wp\/v2\/posts\/55\/revisions\/125"}],"wp:attachment":[{"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}