{"id":52422,"date":"2024-12-03T14:40:17","date_gmt":"2024-12-03T06:40:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52422\/"},"modified":"2024-12-03T14:40:17","modified_gmt":"2024-12-03T06:40:17","slug":"%e8%af%a6%e8%a7%a3%ef%bc%9alinux%e4%b8%ad%e8%ae%be%e7%bd%aessh%e6%97%a0%e5%af%86%e7%a0%81%e5%ae%89%e5%85%a8%e7%99%bb%e5%bd%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52422\/","title":{"rendered":"\u8be6\u89e3\uff1aLinux\u4e2d\u8bbe\u7f6eSSH\u65e0\u5bc6\u7801\u5b89\u5168\u767b\u5f55"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u8be6\u89e3\uff1aLinux\u4e2d\u8bbe\u7f6eSSH\u65e0\u5bc6\u7801\u5b89\u5168\u767b\u5f55<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u8be6\u89e3\uff1aLinux\u4e2d\u8bbe\u7f6eSSH\u65e0\u5bc6\u7801\u5b89\u5168\u767b\u5f55\u300b<\/span>\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591a<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/173225884867402c20614d7.jpg\" class=\"aligncenter\" title=\"\u8be6\u89e3\uff1aLinux\u4e2d\u8bbe\u7f6eSSH\u65e0\u5bc6\u7801\u5b89\u5168\u767b\u5f55\u63d2\u56fe\" alt=\"\u8be6\u89e3\uff1aLinux\u4e2d\u8bbe\u7f6eSSH\u65e0\u5bc6\u7801\u5b89\u5168\u767b\u5f55\u63d2\u56fe\" \/><\/p>\n<p>\u4f5c\u4e3a\u4e00\u540d\u8fd0\u7ef4\u4eba\u5458\u6765\u8bf4\uff0c\u7ba1\u74061-5\u53f0\u673a\u5668\u5c1a\u6709\u4f59\u529b\uff0c\u4f46\u5982\u679c\u662f10\u53f0\u3001100\u53f0\u6216\u66f4\u591a\u670d\u52a1\u5668\uff0c\u662f\u4e0d\u662f\u6bcf\u6b21\u767b\u5f55\u8f93\u5165\u5bc6\u7801\u975e\u5e38\u7e41\u7410\uff0c\u4e14\u8d39\u65f6\u8d39\u529b\uff0c\u65e0\u6cd5\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002\u4eca\u5929\u6211\u4eec\u901a\u8fc7\u4f7f\u7528ssh-kengen\u547d\u4ee4\u751f\u6210\u79c1\u94a5&amp;\u516c\u94a5\u5bf9\uff0c\u76ee\u7684\uff1a\u514d\u5bc6\u7801\u767b\u5f55SSH\u3002\u5176\u7b97\u6cd5\u6709\u4e24\u79cd\uff0c\u5206\u522b\u662fRSA\u548cDSA\u3002<\/p>\n<p>RSA \u662f\u975e\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\uff0c\u53ef\u4ee5\u7528\u6765\u52a0\u5bc6\u548c\u7b7e\u540d\u3002<\/p>\n<p>DSA(Digital Signature Algorithm) \u53ea\u80fd\u7528\u6765\u6570\u5b57\u7b7e\u540d\u7684\u7b97\u6cd5\u3002<\/p>\n<p>\u4ee5\u4e0b\u64cd\u4f5c\u9002\u7528\u4e8eOS\uff1aCentos 7\u3001Ubuntu 17\uff0c\u5176\u4ed6\u7cfb\u7edf\u6ca1\u6d4b\uff0c\u7406\u8bba\u4e0a\u90fd\u53ef\u4ee5\u4f7f\u7528\u3002<\/p>\n<p>\u670d\u52a1\u5668:<\/p>\n<p>10.10.204.63<\/p>\n<p>10.10.204.64<\/p>\n<p>1.\u5982\u4f55\u751f\u6210ssh\u516c\u94a5<\/p>\n<p>\u767b\u5f5510.10.204.63\u670d\u52a1\u5668\u751f\u6210\u516c\u79c1\u5bc6\u94a5\u5bf9\uff1a<\/p>\n<pre>\n[root@10-10-204-63 ~]# ssh-keygen -b 4096 -t rsa\n\nGenerating public\/private rsa key pair.\nEnter file in which to save the key (\/root\/.ssh\/id_rsa):\nCreated directory '\/root\/.ssh'.\nEnter passphrase (empty for no passphrase):\nEnter same passphrase again:\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:qLcoj2nSzq6G9ZpFQZ\/OFqFT+oBDf3ousHkt82F1\/xM root@10-10-204-63.10.10.204.63\nThe key's randomart image is:\n+---[RSA 4096]----+\n|  . . o          |\n| . + = o         |\n|  o B =          |\n|   . X o         |\n|  . o B S .      |\n|  .= * . . .  E  |\n|.oo.B *     .  . |\n|oo+*.O o     ..  |\n|o*O+o o       .. |\n+----[SHA256]-----+\n\n\u4e09\u6b21\u56de\u8f66\u5373\u53ef\u751f\u6210 ssh key\u3002\n<\/pre>\n<p>\u6ce8\u89e3\uff1a<\/p>\n<p>-b \u6307\u5b9a\u5bc6\u94a5\u957f\u5ea6\u3002\u5bf9\u4e8eRSA\u5bc6\u94a5\uff0c\u6700\u5c0f\u8981\u6c42768\u4f4d\uff0c\u9ed8\u8ba4\u662f2048\u4f4d\uff0c\u6700\u957f4096\u5b57\u8282\u3002<\/p>\n<p>-t \u6307\u5b9a\u8981\u521b\u5efa\u7684\u5bc6\u94a5\u7c7b\u578b\u3002\u53ef\u4ee5\u4f7f\u7528\uff1a\u201drsa1\u2033(SSH-1) \u201crsa\u201d(SSH-2) \u201cdsa\u201d(SSH-2)\u3002<\/p>\n<p>2.\u67e5\u770b\u751f\u6210\u7684\u6587\u4ef6<\/p>\n<pre>\n[root@10-10-204-63 ~]# ll .ssh\/\ntotal 8\n-rw------- 1 root root 3243 Nov 25 15:58 id_rsa\n-rw-r--r-- 1 root root  758 Nov 25 15:58 id_rsa.pub\n\n\u8bf4\u660e\uff1a\n\nid_rsa \u79c1\u94a5\n\nid_rsa.pub \u516c\u94a5\n\n<\/pre>\n<p>3.\u5c06\u516c\u94a5\u4e0a\u4f20\u523010.10.204.64<\/p>\n<pre>\n[root@10-10-204-63 ~]# ssh-copy-id -i ~\/.ssh\/id_rsa.pub root@10.10.204.64\n\/usr\/bin\/ssh-copy-id: INFO: Source of key(s) to be installed: \"\/root\/.ssh\/id_rsa.pub\"\nThe authenticity of host '10.10.204.64 (10.10.204.64)' can't be established.\nECDSA key fingerprint is SHA256:\/YI\/L4RT1QH7lkfxMCAkKnvniQslyUl15mOUKUo8K3k.\nECDSA key fingerprint is MD5:6d:b6:f3:93:8e:48:53:24:9d:5d:c2:2a:5f:28:f4:d2.\nAre you sure you want to continue connecting (yes\/no)? yes\u3010\u8f93\u5165yes\u56de\u8f66\u3011\n\/usr\/bin\/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed\n\/usr\/bin\/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys\nroot@10.10.204.64's password:\u3010\u8f93\u5165\u670d\u52a1\u5668\u5bc6\u7801\u56de\u8f66\u3011\n\nNumber of key(s) added: 1\n\nNow try logging into the machine, with:   \"ssh 'root@10.10.204.64'\"\nand check to make sure that only the key(s) you wanted were added.\n<\/pre>\n<p>\u4e0a\u4f20\u6210\u529f\u3002<\/p>\n<p>4.\u4fee\u6539SSH\u914d\u7f6e\u6587\u4ef6<\/p>\n<p>\u767b\u5f5510.28.204.64\u4fee\u6539\uff0c\u64cd\u4f5c\u5982\u4e0b\uff1a<\/p>\n<pre>\n$ vim \/etc\/ssh\/sshd_config\n\n\u53bb\u9664\u4ee5\u4e0b\u6ce8\u91ca\uff1a\n\nRSAAuthentication yes\nPubkeyAuthentication yes\n<\/pre>\n<p>5.\u91cd\u542fSSH\u670d\u52a1<\/p>\n<pre>\n$ systemctl restart sshd\n<\/pre>\n<p>6.\u6d4b\u8bd5\u514d\u5bc6\u7801\u767b\u5f5510.10.204.64<\/p>\n<pre>\n[root@10-10-204-63 ~]# ssh 'root@10.10.204.64'\nLast failed login: Sat Nov 25 16:09:48 CST 2017 from 83.234.149.66 on ssh:notty\nThere was 1 failed login attempt since the last successful login.\nLast login: Sat Nov 25 15:57:33 2017 from 36.7.69.84\n[root@10-10-204-64 ~]#\n<\/pre>\n<p>\u5728\u4e0d\u8f93\u5165\u5bc6\u7801\u7684\u60c5\u51b5\u4e0b\u6210\u529f\u767b\u5f55\u3002<\/p>\n<p>\u767b\u9646\u6210\u529f\u540e\uff0c\u5efa\u8bae\u572810.10.204.64\u670d\u52a1\u5668\u4e0a\u4e5f\u751f\u6210ssh\u516c\u94a5\uff0c\u5e76\u4e0a\u4f20\u523010.10.204.63\u670d\u52a1\u5668\uff0c\u8fd9\u6837\u4ee5\u6765\u6211\u4eec\u5c31\u53ef\u4ee5\u76f8\u4e92\u514d\u5bc6\u7801SSH\u767b\u9646\u3002\u591a\u53f0\u670d\u52a1\u5668\u4ea6\u662f\u5982\u6b64\u3002<\/p>\n<p>7.\u67e5\u770b\u516c\u94a5<\/p>\n<pre>\n[root@10-10-204-64 ~]# ll \/root\/.ssh\/\ntotal 8\n-rw-------  1 root root 758 Nov 25 16:08 authorized_keys\n-rw-r--r--. 1 root root 175 Aug  9 09:19 known_hosts\n<\/pre>\n<p>authorized_keys\u662f\u521a\u4e0a\u4f20\u8fc7\u6765\u7684\u516c\u94a5\u540d\u79f0<\/p>\n<p>8.\u5982\u679c\u516c\u94a5\u4e22\u5931\uff0c\u53ef\u4ee5\u4f7f\u7528\u79c1\u94a5\u518d\u6b21\u751f\u6210\u516c\u94a5\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre>\n[root@10-10-204-63 ~]# ssh-keygen -y -f ~\/.ssh\/id_rsa &gt; ~\/.ssh\/id_rsa.pub\n<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8be6\u89e3\uff1aLinux\u4e2d\u8bbe\u7f6eSSH\u65e0\u5bc6\u7801\u5b89\u5168\u767b\u5f55 \u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587\u300a\u8be6\u89e3\uff1aLinux\u4e2d\u8bbe\u7f6eSSH\u65e0\u5bc6\u7801\u5b89\u5168\u767b\u5f55\u300b\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591a\u6587\u7ae0\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~ \u4f5c\u4e3a\u4e00\u540d\u8fd0\u7ef4\u4eba\u5458\u6765\u8bf4\uff0c\u7ba1\u74061-5\u53f0\u673a\u5668\u5c1a\u6709\u4f59\u529b\uff0c\u4f46\u5982\u679c\u662f10\u53f0\u3001100\u53f0\u6216\u66f4\u591a\u670d\u52a1\u5668\uff0c\u662f\u4e0d\u662f\u6bcf\u6b21\u767b\u5f55\u8f93\u5165\u5bc6\u7801\u975e\u5e38\u7e41\u7410\uff0c\u4e14\u8d39\u65f6\u8d39\u529b\uff0c\u65e0\u6cd5\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002\u4eca\u5929\u6211\u4eec\u901a\u8fc7\u4f7f\u7528ssh-kengen\u547d\u4ee4\u751f\u6210\u79c1\u94a5&amp;\u516c\u94a5\u5bf9\uff0c\u76ee\u7684\uff1a\u514d\u5bc6\u7801\u767b\u5f55SSH\u3002\u5176\u7b97\u6cd5\u6709\u4e24\u79cd\uff0c\u5206\u522b\u662fRSA\u548cDSA\u3002 RSA \u662f\u975e\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\uff0c\u53ef\u4ee5\u7528\u6765\u52a0\u5bc6\u548c\u7b7e\u540d\u3002 DSA(Digital Signature Algorithm) \u53ea\u80fd\u7528\u6765\u6570\u5b57\u7b7e\u540d\u7684\u7b97\u6cd5\u3002 \u4ee5\u4e0b\u64cd\u4f5c\u9002\u7528\u4e8eOS\uff1aCentos 7\u3001Ubuntu 17\uff0c\u5176\u4ed6\u7cfb\u7edf\u6ca1\u6d4b\uff0c\u7406\u8bba\u4e0a\u90fd\u53ef\u4ee5\u4f7f\u7528\u3002 \u670d\u52a1\u5668: 10.10.204.63 10.10.204.64 1.\u5982\u4f55\u751f\u6210ssh\u516c\u94a5 \u767b\u5f5510.10.204.63\u670d\u52a1\u5668\u751f\u6210\u516c\u79c1\u5bc6\u94a5\u5bf9\uff1a [root@10-10-204-63 ~]# ssh-keygen -b 4096 -t rsa Generating public\/private rsa key pair. Enter file in which to save the key (\/root\/.ssh\/id_rsa): Created directory &#8216;\/root\/.ssh&#8217;. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-52422","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52422"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52422\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}