{"id":256,"date":"2018-03-13T09:58:09","date_gmt":"2018-03-13T01:58:09","guid":{"rendered":"http:\/\/www.max-shu.com\/blog\/?p=256"},"modified":"2018-03-13T09:58:09","modified_gmt":"2018-03-13T01:58:09","slug":"ssh-key%e7%9a%84passphrases%e4%b8%8d%e7%94%a8%e6%af%8f%e6%ac%a1%e9%83%bd%e8%be%93%e5%85%a5","status":"publish","type":"post","link":"http:\/\/www.max-shu.com\/blog\/?p=256","title":{"rendered":"SSH Key\u7684passphrases\u4e0d\u7528\u6bcf\u6b21\u90fd\u8f93\u5165"},"content":{"rendered":"<p>\u4f7f\u7528Key\u65b9\u5f0f\u4ecelinux\u670d\u52a1\u5668\u767b\u5f55\u5230\u522b\u7684linux\u670d\u52a1\u5668\u65f6\uff0c\u5982\u679c\u5efa\u7acbkey\u7684\u65f6\u5019\u5df2\u7ecf\u8f93\u5165\u4e86Passphrase\uff0c\u5219\u6bcf\u6b21\u767b\u5f55\u65f6\u603b\u662f\u63d0\u793a\u8f93\u5165passphrase\u53e3\u4ee4\uff0c\u5f88\u662f\u4e0d\u65b9\u4fbf\u3002<\/p>\n<p>\u6709\u4e2a\u529e\u6cd5\u53ef\u4ee5\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u5c31\u662f\u4f7f\u7528ssh-agent\uff0c\u4ed6\u53ef\u4ee5\u4fdd\u5b58passphrase\uff0c\u53ea\u7528\u8f93\u5165\u4e00\u6b21\u5c31ok\u4e86\u3002<\/p>\n<p><b>\u589e\u52a0\u6216\u4fee\u6539passphrase\uff1a<\/b><\/p>\n<p>\u53ef\u4ee5\u5728key\u79c1\u94a5\u548c\u516c\u94a5\u6587\u4ef6\u91cc\u9762\u589e\u52a0\u6216\u4fee\u6539passphrase\uff1a<\/p>\n<p>$ ssh-keygen -p<br \/>\nEnter file in which the key is (\/Users\/tekkub\/.ssh\/id_rsa):<br \/>\nKey has comment &#8216;\/Users\/tekkub\/.ssh\/id_rsa&#8217;<br \/>\nEnter new passphrase (empty for no passphrase):<br \/>\nEnter same passphrase again:<br \/>\nYour identification has been saved with the new passphrase.<\/p>\n<p>\u5982\u679cid_rsa\u91cc\u9762\u5df2\u7ecf\u6709passphrase\u4e86\uff0c\u5219\u4f1a\u8981\u6c42\u8f93\u5165\u8001\u7684passphrase\u3002<\/p>\n<p><b>\u6bcf\u6b21\u767b\u5f55\u81ea\u52a8\u8fd0\u884cssh-agent\uff1a<\/b><\/p>\n<p>\u4fee\u6539\u7528\u6237~\/.profile\u6216\u8005~\/.bashrc\u6587\u4ef6\uff0c\u589e\u52a0\u4e0b\u5217\u5185\u5bb9\uff1a<\/p>\n<p>SSH_ENV=&#8221;$HOME\/.ssh\/environment&#8221;<\/p>\n<p># start the ssh-agent<br \/>\nfunction start_agent {<br \/>\necho &#8220;Initializing new SSH agent&#8230;&#8221;<br \/>\n# spawn ssh-agent<br \/>\nssh-agent | sed &#8216;s\/^echo\/#echo\/&#8217; &gt; &#8220;$SSH_ENV&#8221;<br \/>\necho succeeded<br \/>\nchmod 600 &#8220;$SSH_ENV&#8221;<br \/>\n. &#8220;$SSH_ENV&#8221; &gt; \/dev\/null<br \/>\nssh-add<br \/>\n}<\/p>\n<p># test for identities<br \/>\nfunction test_identities {<br \/>\n# test whether standard identities have been added to the agent already<br \/>\nssh-add -l | grep &#8220;The agent has no identities&#8221; &gt; \/dev\/null<br \/>\nif [ $? -eq 0 ]; then<br \/>\nssh-add<br \/>\n# $SSH_AUTH_SOCK broken so we start a new proper agent<br \/>\nif [ $? -eq 2 ];then<br \/>\nstart_agent<br \/>\nfi<br \/>\nfi<br \/>\n}<\/p>\n<p># check for running ssh-agent with proper $SSH_AGENT_PID<br \/>\nif [ -n &#8220;$SSH_AGENT_PID&#8221; ]; then<br \/>\nps -ef | grep &#8220;$SSH_AGENT_PID&#8221; | grep ssh-agent &gt; \/dev\/null<br \/>\nif [ $? -eq 0 ]; then<br \/>\ntest_identities<br \/>\nfi<br \/>\n# if $SSH_AGENT_PID is not properly set, we might be able to load one from<br \/>\n# $SSH_ENV<br \/>\nelse<br \/>\nif [ -f &#8220;$SSH_ENV&#8221; ]; then<br \/>\n. &#8220;$SSH_ENV&#8221; &gt; \/dev\/null<br \/>\nfi<br \/>\nps -ef | grep &#8220;$SSH_AGENT_PID&#8221; | grep -v grep | grep ssh-agent &gt; \/dev\/null<br \/>\nif [ $? -eq 0 ]; then<br \/>\ntest_identities<br \/>\nelse<br \/>\nstart_agent<br \/>\nfi<br \/>\nfi<\/p>\n<p>\u5982\u679c\u4e0d\u662f\u7f3a\u7701\u540d\u5b57\u7684key\u6587\u4ef6\u6216\u8def\u5f84\uff0c\u5219\u8981\u4fee\u6539ssh-add\u547d\u4ee4\u884c\uff0c\u589e\u52a0key\u6587\u4ef6\u540d\u5230\u540e\u9762\u3002\u6bcf\u6b21\u767b\u5f55\u540e\u53ef\u4ee5\u770b\u5230\u591a\u4e86\u4e00\u4e2assh-agent\u8fdb\u7a0b\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528Key\u65b9\u5f0f\u4ecelinux\u670d\u52a1\u5668\u767b\u5f55\u5230\u522b\u7684linux\u670d\u52a1\u5668\u65f6\uff0c\u5982\u679c\u5efa\u7acbkey\u7684\u65f6\u5019\u5df2\u7ecf\u8f93\u5165\u4e86Passphras &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[172,180,101,179],"class_list":["post-256","post","type-post","status-publish","format-standard","hentry","category-linuxandroid","tag-key","tag-passphrase","tag-ssh","tag-ssh-agent"],"views":4601,"_links":{"self":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=256"}],"version-history":[{"count":1,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/256\/revisions"}],"predecessor-version":[{"id":257,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/256\/revisions\/257"}],"wp:attachment":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}