{"id":56,"date":"2024-03-11T07:57:15","date_gmt":"2024-03-10T23:57:15","guid":{"rendered":"https:\/\/www.cutegameit.com\/linux\/?p=63"},"modified":"2025-08-29T15:17:13","modified_gmt":"2025-08-29T07:17:13","slug":"ssh-key-%e7%9a%84%e5%bb%ba%e7%ab%8b","status":"publish","type":"post","link":"https:\/\/www.cutexyz.com\/edu\/linux2402\/?p=56","title":{"rendered":"ssh key \u7684\u5efa\u7acb (Linux &amp; Mac computer)"},"content":{"rendered":"\n<pre class=\"wp-block-code has-base-3-color has-contrast-background-color has-text-color has-background\"><code>\u8a2d\u5b9a ssh key \n\u5148\u5728 client \u7684\u7684\u96fb\u8166\u5167\u9032\u884c\u4ee5\u4e0b\u8a2d\u5b9a\n\nmkdir -p ~\/.ssh\nchmod 700 ~\/.ssh\n\nssh-keygen\n\u8f38\u5165\u76f8\u95dc\u8a0a\u606f(\u57fa\u672c\u4e0a\u5c31\u662f\u4e00\u76f4 enter)\nX \u6ce8\u610f\u6ce8\u610f X\nEnter passphrase (empty for no passphrase): \u9019\u500b\u4e0d\u8981\u8f38\u5165, \u4e0d\u7136\u6bcf\u6b21\u4f7f\u7528\u91d1\u9470\u90fd\u8981\u8f38\u5165\u5bc6\u78bc\n\u96d6\u7136\u5b89\u5168\u6027\u5927\u589e, \u4f46\u662f\u9ebb\u7169\u5ea6\u4e5f\u5927\u589e!\n\n\u5b8c\u6210\u4e4b\u5f8c, \u4f60\u5230 ~\/.ssh \u76ee\u9304\u4e0b\u9762\u53bb\u770b \u5c31\u6703\u770b\u5230\u5169\u500b\u6a94\u6848\n\nid_rsa.pub (\u516c\u9470)\nid_rsa (\u79c1\u9470)\n\n\u63a5\u4e0b\u4f86 ssh \u9032\u5230 Server \u4e26\u4f7f\u7528\u6240\u8981\u4f7f\u7528\u91d1\u9470\u7684\u5e33\u865f\nvi  ~\/.ssh\/authorized_keys \n\u5c07\u516c\u9470\u5167\u5bb9\u8cbc\u4e0a\u5132\u5b58\n\n\u9032\u884c\u6a94\u6848\u6b0a\u9650\u8a2d\u5b9a\n\u628a ~\/.ssh \u76ee\u9304\u8a2d\u6210 700\uff0cauthorized_keys \u6a94\u6848\u8a2d\u6210 640\n\u6ce8\u610f ~\/.ssh\u76ee\u9304 \u8207 authorized_keys \u6a94\u6848\u7684\u6b0a\u9650\u662f\u5426\u70ba\u5e33\u6236\u672c\u4eba\n\n\u63a5\u4e0b\u4f86\u5c31\u53ef\u4ee5\u7528\nssh -i \u79c1\u9470\u4f4d\u7f6e xxx@server_ip\n\u9032\u884c\u9023\u7dda\u800c\u4e0d\u7528\u8f38\u5165\u5bc6\u78bc\n\n\u5982\u679c\u8981\u63d0\u9ad8\u5b89\u5168\u6027, \u53ef\u505c\u7528\u5bc6\u78bc\u8a8d\u8b49\u7684\u767b\u5165\u65b9\u5f0f\nvi \/etc\/ssh\/sshd_config\n\u4fee\u6539\u4ee5\u4e0b\u5167\u5bb9\nPasswordAuthentication no\nPubkeyAuthentication yes\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","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-56","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\/56","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=56"}],"version-history":[{"count":1,"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=\/wp\/v2\/posts\/56\/revisions"}],"predecessor-version":[{"id":60,"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=\/wp\/v2\/posts\/56\/revisions\/60"}],"wp:attachment":[{"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cutexyz.com\/edu\/linux2402\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}