{"id":3349,"date":"2020-11-23T15:12:04","date_gmt":"2020-11-23T07:12:04","guid":{"rendered":"https:\/\/www.liangliang.org.cn\/?p=3349"},"modified":"2020-11-23T15:12:04","modified_gmt":"2020-11-23T07:12:04","slug":"ssh-keygen","status":"publish","type":"post","link":"https:\/\/www.liangliang.org.cn\/?p=3349","title":{"rendered":"ssh-keygen"},"content":{"rendered":"<p>ssh-keygen\u7528\u6765\u751f\u6210ssh\u516c\u94a5\u8ba4\u8bc1\u6240\u9700\u7684\u516c\u94a5\u548c\u79c1\u94a5\u6587\u4ef6\u3002<\/p>\n<p>ssh\u79d8\u94a5\u767b\u5f55\u7279\u70b9\uff1a<strong>1.\u5b89\u5168\uff1b2.\u514d\u8f93\u5bc6\u7801\u3002<\/strong><br \/>\n\u5bf9\u4e8e\u5b89\u5168\u7ea7\u522b\u8f83\u9ad8\u7684\u670d\u52a1\u5668\uff0c\u5efa\u8bae\u914d\u597dssh\u767b\u5f55\u540e\u7981\u6389\u5bc6\u7801\u767b\u5f55\u3002<br \/>\n\u7f3a\u70b9\uff1a\u7565\u7e41\u7410\u3002\u5982\u679c\u4f60\u7684\u53ea\u662f\u4e34\u65f6\u767b\u5f55\u4e00\u6b21\uff0c\u90a3\u4e48\u8fd8\u662f\u5bc6\u7801\u5427\u3002<\/p>\n<h3>\u4e00\u3001\u751f\u6210\u79d8\u94a5<\/h3>\n<blockquote>\n<p>\u79d8\u94a5\u5bf9\u9700\u8981\u5728\u4f60\u81ea\u5df1\u7684\u673a\u5668\u4e0a\u751f\u6210\uff0c\u7136\u540e\u628a\u516c\u94a5\u653e\u5230\u670d\u52a1\u5668\u76f8\u5e94\u7528\u6237\u7684~\/.ssh\u76ee\u5f55<\/p>\n<\/blockquote>\n<p>\u6267\u884c\u4e0b\u9762\u547d\u4ee4,\u9ed8\u8ba4\u751f\u6210\u4f4d\u7f6e\u662f~\/.ssh<\/p>\n<pre><code class=\"language-bash\">ssh-keygen<\/code><\/pre>\n<p>\u7cfb\u7edf\u4f1a\u8be2\u95ee\u4f60\u6587\u4ef6\u540d\u548c\u79d8\u94a5\u5bc6\u7801\uff0c\u53ef\u4ee5\u4e00\u8def\u56de\u8f66\u8fc7\u53bb\uff0c\u4f1a\u751f\u6210\u4e24\u4e2a\u6587\u4ef6\uff1a<\/p>\n<ul>\n<li>id_rsa \u79c1\u94a5<\/li>\n<li>id_rsa.pub \u516c\u94a5<\/li>\n<\/ul>\n<p>\u9ed8\u8ba4\u4f7f\u7528rsa\u7b97\u6cd5\uff0c\u4f60\u4e5f\u53ef\u4ee5\u7528\u6bd4\u8f83\u8be6\u7ec6\u7684\u6307\u4ee4\uff0c\u5982<\/p>\n<pre><code class=\"language-bash\">ssh-keygen -t rsa -b 1024 -f yourkeyname -C &quot;\u5907\u6ce8&quot;<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>\u53c2\u6570<\/th>\n<th>\u89e3\u91ca<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>-b<\/td>\n<td>\u91c7\u7528\u957f\u5ea61024bit\u7684\u5bc6\u94a5\u5bf9,b=bits,\u6700\u957f4096\uff0c\u4e0d\u8fc7\u6ca1\u5565\u5fc5\u8981<\/td>\n<\/tr>\n<tr>\n<td>-t rsa<\/td>\n<td>\u91c7\u7528rsa\u52a0\u5bc6\u65b9\u5f0f,t=type<\/td>\n<\/tr>\n<tr>\n<td>-f<\/td>\n<td>\u751f\u6210\u6587\u4ef6\u540d,f=output_keyfiles<\/td>\n<\/tr>\n<tr>\n<td>-C<\/td>\n<td>\u5907\u6ce8\uff0cC=comment<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u66f4\u591a\u53c2\u6570\u53ef\u8fd0\u884c man ssh-keygen<\/p>\n<h3>\u4e8c\u3001\u5728\u670d\u52a1\u5668\u4e0a\u5b89\u88c5\u79d8\u94a5<\/h3>\n<p>\u628a\u4e0a\u4e00\u6b65\u751f\u6210\u7684\u516c\u94a5\u53d1\u9001\u5230\u670d\u52a1\u5668(scp,FillZilla\u7b49)\u4e0a\uff0c\u7136\u540e\u5728\u670d\u52a1\u5668\u4e0a\u6267\u884c\u4e0b\u9762\u547d\u4ee4<\/p>\n<pre><code class=\"language-bash\">cat id_rsa.pub &gt;&gt; ~\/.ssh\/authorized_keys<\/code><\/pre>\n<p>\u5982\u6b64\u4fbf\u5b8c\u6210\u4e86\u516c\u94a5\u5b89\u88c5\uff0c\u6709\u4e2a\u5c0f\u5751\u503c\u5f97\u4e00\u63d0\uff1a<strong>authenrized_keys\u7684\u6743\u9650\u5fc5\u987b\u662f600\u6216\u66f4\u5c0f<\/strong>\uff0c\u5426\u5219\u4f1a\u8fde\u63a5\u5931\u8d25\u3002<br \/>\n\u4fdd\u9669\u8d77\u89c1\uff0c\u6267\u884c\u4e0b\u9762\u547d\u4ee4<\/p>\n<pre><code class=\"language-bash\">chmod 600 ~\/.ssh\/authorized_keys\nchmod 700 ~\/.ssh<\/code><\/pre>\n<p><strong>\u53e6\u5916\uff0c.ssh\u76ee\u5f55\u7684owner\u5fc5\u987b\u662fssh\u767b\u5f55\u7528\u6237\uff0c\u4e0d\u80fd\u662froot<\/strong><\/p>\n<h4>\u670d\u52a1\u5668ssh\u914d\u7f6e<\/h4>\n<p>\u4fee\u6539\u670d\u52a1\u5668\u4e0a\u7684ssh\u914d\u7f6e\u6587\u4ef6\uff0c\u4f4d\u7f6e\uff1a\/etc\/ssh\/sshd_config<\/p>\n<pre><code class=\"language-vim\">RSAAuthentication yes\nPubkeyAuthentication yes\n\nPermitRootLogin no \/\/\u7981\u6b62root\u767b\u5f55\nPasswordAuthentication yes \/\/\u5141\u8bb8\u5bc6\u7801\u767b\u5f55\uff0c\u6839\u636e\u4f60\u7684\u60c5\u51b5\u8bbe\u7f6e<\/code><\/pre>\n<p>\u7136\u540e\u91cd\u542fssh\u670d\u52a1<\/p>\n<pre><code class=\"language-bash\">service sshd restart<\/code><\/pre>\n<h3>\u4e09\u3001\u8fde\u63a5\u670d\u52a1\u5668<\/h3>\n<h6>\u65b9\u6cd51\uff1a \u76f4\u63a5ssh<\/h6>\n<pre><code class=\"language-bash\">ssh -i ~\/.ssh\/id_rsa -p 22 user@yourservername<\/code><\/pre>\n<h6>\u65b9\u6cd52\uff08\u63a8\u8350\uff09\uff1a\u4fee\u6539~\/.ssh\/config<\/h6>\n<pre><code class=\"language-undefined\">Host server_alias(\u4f60\u7684\u670d\u52a1\u5668\u522b\u540d)\nHostName test.com\/192.168.1.1(\u57df\u540d\u6216IP)\nPort 22\nUser user\nIdentifier id_rsa<\/code><\/pre>\n<p>\u4fdd\u5b58\u540e\uff0c\u767b\u5f55\u65f6\u53ea\u9700\u6267\u884c<\/p>\n<pre><code class=\"language-bash\">ssh server_alias<\/code><\/pre>\n<p>\u591a\u4e2a\u670d\u52a1\u5668\u53e6\u8d77\u4e00\u884c\u7eed\u5199\u5c31\u884c\u4e86\uff0c\u5c31\u662f\u8fd9\u4e48\u7b80\u5355\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ssh-keygen\u7528\u6765\u751f\u6210ssh\u516c\u94a5\u8ba4\u8bc1\u6240\u9700\u7684\u516c\u94a5\u548c\u79c1\u94a5\u6587\u4ef6\u3002 ssh\u79d8\u94a5\u767b\u5f55\u7279\u70b9\uff1a1.\u5b89\u5168\uff1b2.\u514d\u8f93\u5bc6\u7801\u3002 \u5bf9\u4e8e\u5b89\u5168\u7ea7\u522b\u8f83\u9ad8\u7684\u670d\u52a1\u5668\uff0c\u5efa\u8bae\u914d\u597dssh\u767b\u5f55\u540e\u7981\u6389\u5bc6\u7801\u767b\u5f55\u3002 \u7f3a\u70b9\uff1a\u7565\u7e41\u7410\u3002\u5982\u679c\u4f60\u7684\u53ea\u662f&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[60],"tags":[],"class_list":["post-3349","post","type-post","status-publish","format-standard","hentry","category-ssh"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/3349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3349"}],"version-history":[{"count":1,"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/3349\/revisions"}],"predecessor-version":[{"id":3350,"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/3349\/revisions\/3350"}],"wp:attachment":[{"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liangliang.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}