{"id":209,"date":"2023-08-24T22:41:21","date_gmt":"2023-08-24T14:41:21","guid":{"rendered":"https:\/\/miie.net\/?p=209"},"modified":"2023-08-24T22:41:21","modified_gmt":"2023-08-24T14:41:21","slug":"debian-ssh-nopassword","status":"publish","type":"post","link":"https:\/\/diji.net\/?p=209","title":{"rendered":"DEBIAN\u542f\u7528\u5bc6\u94a5\u767b\u9646"},"content":{"rendered":"<p>\u5728Linux\u7cfb\u7edf\u91cc\u9762\uff0c\u5bc6\u94a5\u767b\u5f55\u662f\u6bd4\u8f83\u5b89\u5168\u7684\u4e00\u79cd\u65b9\u6cd5\uff0c\u8fd9\u91cc\u53ea\u8bf4\u5728debian 10\u91cc\u9762\uff0c\u5982\u4f55\u7528\u5bc6\u94a5\u8fdb\u884c\u767b\u5f55\u3002<\/p>\n<p>\u4e00\uff0c\u7528ssh\u65b9\u5f0f\u767b\u5f55\u5230debian\u7cfb\u7edf\uff0c\u5efa\u8bae\u7528putty\u8fd9\u4e2a\u8f6f\u4ef6<\/p>\n<p>\u4e8c\uff0c\u751f\u6210\u5bc6\u94a5\uff0c\u8f93\u5165<br \/>\nssh-keygen -t rsa(\u751f\u6210\u5bc6\u94a5)<\/p>\n<p>\u6309\u4e24\u6b21\u56de\u8f66\uff0c\u5373\u53ef\u5b8c\u6574\u7684\u751f\u6210\u5bc6\u94a5\u4e86\uff0c\u5c31\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\uff08\u4e00\u822c\u4e3aroot\u76ee\u5f55\uff09\u751f\u6210\u4e00\u4e2a.ssh\u7684\u6587\u4ef6\u5939<\/p>\n<p><img decoding=\"async\" src=\"\/img\/20230824-debian-ssh-use-key\/01.png\" alt=\"\" \/><\/p>\n<p>\u4e09\uff0c\u8bbe\u7f6e\u5bc6\u94a5<\/p>\n<p>cd .ssh<br \/>\n\u67e5\u770b\u76ee\u5f55\u5185\u6709\u54ea\u4e9b\u6587\u4ef6<br \/>\nls -la<br \/>\n\u53d1\u73b0\u6709id-rsa\u548cid-rsa.pub\u4e24\u4e2a\u6587\u4ef6\uff0c\u5176\u4e2d id-rsa\u4e3a\u79c1\u94a5\uff0c id-rsa.pub \u5219\u4e3a\u516c\u94a5<\/p>\n<p>\u628a\u516c\u94a5\u6539\u4e00\u4e2a\u6587\u4ef6\u540d<br \/>\ncat id_rsa.pub &gt;&gt; authorized_keys<\/p>\n<p>\u628a\u6539\u597d\u7684\u6587\u4ef6\u7ed9\u4e0a\u6743\u9650<br \/>\nchmod 600 authorized_keys<br \/>\nchmod 700 ~\/.ssh<\/p>\n<p>\u56db\uff0c\u8bbe\u7f6e\u79c1\u94a5<br \/>\n\u5728.ssh\u76ee\u5f55\u5185\uff0c\u67e5\u770b\u79c1\u94a5id_rsa\u7684\u5185\u5bb9 \uff0c\u547d\u4ee4\uff1acat id_rsa<\/p>\n<p><img decoding=\"async\" src=\"\/img\/20230824-debian-ssh-use-key\/02.png\" alt=\"\" \/><\/p>\n<p>cat id_rsa\u67e5\u770b\u5bc6\u94a5\u5185\u5bb9<br \/>\n\u7136\u540e\u628a\u4e0b\u9762\u7684\u6240\u6709\u7684\u5185\u5bb9\u590d\u5236\u5230\u4e00\u4e2a\u8bb0\u4e8b\u672c\u5185\uff0c\u547d\u540d\u4e3a\uff1aid_rsa<\/p>\n<p>\u4e94\uff0c\u8bbe\u7f6essh\u7528\u5bc6\u94a5\u767b\u5f55\u7684\u914d\u7f6e<\/p>\n<p>nano \/etc\/ssh\/sshd_config<\/p>\n<p>\u628a\u4ee5\u4e0b\u4e24\u4e2a\u524d\u9762\u7684\u6ce8\u91ca\u53bb\u6389\uff0c\u8ba9\u5176\u751f\u6548<br \/>\nPubkeyAuthentication yes<br \/>\nAuthorizedKeysFile .ssh\/authorized_keys<\/p>\n<p><img decoding=\"async\" src=\"\/img\/20230824-debian-ssh-use-key\/03.png\" alt=\"\" \/><\/p>\n<p>\u7136\u540e\u91cd\u542fssh<\/p>\n<p>service sshd restart<br \/>\n\u6216\u8005<br \/>\nsystemctl restart sshd.service<\/p>\n<p>\u516d\uff0c\u8bbe\u7f6e\u79c1\u94a5<\/p>\n<p><a href=\"https:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/latest.html\"><a href=\"https:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/latest.html\"><a href=\"https:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/latest.html\">https:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/latest.html<\/a><\/a><\/a><br \/>\n\u4e0b\u8f7dputtygen.exe\uff0c\u628a\u79c1\u94a5\u8f6c\u6362\u4e3aputty\u53ef\u7528\u6a21\u5f0f<\/p>\n<p>\u70b9File-----&gt;Load Private key\uff0c\u627e\u5230\u521a\u624d\u53e6\u5b58\u4e3a\u7684id_rsa\u6587\u4ef6\uff0c\u6253\u5f00\uff0c\u5982\u4e0b\uff0c\u70b9Save private key\uff0c\u7136\u540e\u4fdd\u5b58\u4e3a\u4e00\u4e2appk\u7684\u6587\u4ef6<\/p>\n<p><img decoding=\"async\" src=\"\/img\/20230824-debian-ssh-use-key\/04.png\" alt=\"\" \/><\/p>\n<p>\u4e03\uff0c\u7528putty\u91c7\u7528\u5bc6\u94a5\u767b\u5f55\uff0c\u628a\u4e0a\u4e00\u6b65\u4fdd\u5b58\u7684ppk\u6587\u4ef6\u9009\u4e2d<\/p>\n<p><img decoding=\"async\" src=\"\/img\/20230824-debian-ssh-use-key\/05.png\" alt=\"\" \/><\/p>\n<p>\u5982\u4e0b\u56fe\uff0c\u76f4\u63a5\u8f93\u5165root\u5c31\u53ef\u4ee5\u767b\u5f55\u4e86\uff0c\u4e0d\u7528\u5bc6\u7801<\/p>\n<p><img decoding=\"async\" src=\"\/img\/20230824-debian-ssh-use-key\/06.png\" alt=\"\" \/><\/p>\n<p>\u7136\u540e\u5728\/etc\/ssh\/sshd_conifg\u91cc\u9762\uff0c\u628a\u5bc6\u7801\u767b\u5f55\u6539\u4e3ano\uff0c\u5373\u4e3a\u4e0d\u7528\u5bc6\u7801\u767b\u5f55<\/p>\n<p>PasswordAuthentication no<\/p>\n<p><img decoding=\"async\" src=\"\/img\/20230824-debian-ssh-use-key\/07.png\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Linux\u7cfb\u7edf\u91cc\u9762\uff0c\u5bc6\u94a5\u767b\u5f55\u662f\u6bd4\u8f83\u5b89\u5168\u7684\u4e00\u79cd\u65b9\u6cd5\uff0c\u8fd9\u91cc\u53ea\u8bf4\u5728debian 10\u91cc\u9762\uff0c\u5982\u4f55\u7528\u5bc6\u94a5\u8fdb\u884c\u767b\u5f55\u3002 \u4e00\uff0c\u7528ssh\u65b9\u5f0f\u767b\u5f55\u5230debian\u7cfb\u7edf\uff0c\u5efa\u8bae\u7528putty\u8fd9\u4e2a\u8f6f\u4ef6 \u4e8c\uff0c\u751f\u6210\u5bc6\u94a5\uff0c\u8f93\u5165 ssh-keygen -t rsa(\u751f\u6210\u5bc6\u94a5) \u6309\u4e24\u6b21\u56de\u8f66\uff0c\u5373\u53ef\u5b8c\u6574\u7684\u751f\u6210\u5bc6\u94a5\u4e86\uff0c\u5c31\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\uff08\u4e00\u822c\u4e3aroot\u76ee\u5f55\uff09\u751f\u6210\u4e00\u4e2a.ssh\u7684\u6587\u4ef6\u5939 \u4e09\uff0c\u8bbe\u7f6e\u5bc6\u94a5 cd .ssh \u67e5\u770b\u76ee\u5f55\u5185\u6709\u54ea\u4e9b\u6587\u4ef6 ls -la \u53d1\u73b0\u6709id-rsa\u548cid-rsa.pub\u4e24\u4e2a\u6587\u4ef6\uff0c\u5176\u4e2d id-rsa\u4e3a\u79c1\u94a5\uff0c id-rsa.pub \u5219\u4e3a\u516c\u94a5 \u628a\u516c\u94a5\u6539\u4e00\u4e2a\u6587\u4ef6\u540d cat id_rsa.pub &gt;&gt; authorized_keys \u628a\u6539\u597d\u7684\u6587\u4ef6\u7ed9\u4e0a\u6743\u9650 chmod 600 authorized_keys chmod 700 ~\/.ssh \u56db\uff0c\u8bbe\u7f6e\u79c1\u94a5 \u5728.ssh\u76ee\u5f55\u5185\uff0c\u67e5\u770b\u79c1\u94a5id_rsa\u7684\u5185\u5bb9 \uff0c\u547d\u4ee4\uff1acat id_rsa cat id_rsa\u67e5\u770b\u5bc6\u94a5\u5185\u5bb9 \u7136\u540e\u628a\u4e0b\u9762\u7684\u6240\u6709\u7684\u5185\u5bb9\u590d\u5236\u5230\u4e00\u4e2a\u8bb0\u4e8b\u672c\u5185\uff0c\u547d\u540d\u4e3a\uff1aid_rsa \u4e94\uff0c\u8bbe\u7f6essh\u7528\u5bc6\u94a5\u767b\u5f55\u7684\u914d\u7f6e nano \/etc\/ssh\/sshd_config \u628a\u4ee5\u4e0b\u4e24\u4e2a\u524d\u9762\u7684\u6ce8\u91ca\u53bb\u6389\uff0c\u8ba9\u5176\u751f\u6548 PubkeyAuthentication yes AuthorizedKeysFile .ssh\/authorized_keys \u7136\u540e\u91cd\u542fssh service sshd restart \u6216\u8005 systemctl restart sshd.service \u516d\uff0c\u8bbe\u7f6e\u79c1\u94a5 https:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/latest.html [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-209","post","type-post","status-publish","format-standard","hentry","category-debian"],"_links":{"self":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=209"}],"version-history":[{"count":0,"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/209\/revisions"}],"wp:attachment":[{"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}