{"id":7837,"date":"2014-08-07T08:12:54","date_gmt":"2014-08-07T00:12:54","guid":{"rendered":"http:\/\/ihower.tw\/blog\/?p=7837"},"modified":"2025-07-04T08:05:01","modified_gmt":"2025-07-04T00:05:01","slug":"ssh-agent-forwarding","status":"publish","type":"post","link":"https:\/\/ihower.tw\/blog\/7837-ssh-agent-forwarding","title":{"rendered":"SSH agent forwarding \u7684\u61c9\u7528"},"content":{"rendered":"<p>SSH agent forwarding \u53ef\u4ee5\u8b93\u672c\u5730\u7684 SSH Key \u5728\u9060\u7aef Server \u4e0a\u9032\u884c\u8f49\u9001\uff0c\u4e5f\u5c31\u662f\u7576\u4f60\u9700\u8981\u5728\u9078\u7aef Server \u4e0a\u4f7f\u7528 SSH Key \u6642\uff0c\u5c31\u4e0d\u9700\u8981\u5c07\u4f60\u7684 key pair \u624b\u52d5\u8907\u88fd\u5230 server \u4e0a\uff0c\u662f\u500b\u66a8\u65b9\u4fbf\u53c8\u5b89\u5168\u7684\u4f5c\u6cd5\u3002<\/p>\n<p>\u8209\u4f8b\u4f86\u8aaa\uff0c\u9996\u5148 SSH \u767b\u5165\u9032 Server1\uff0c\u63a5\u8457\u5728 Server1 \u4e0a\u767b\u5165 Server2 \u6642\uff0c\u5c31\u6703\u81ea\u52d5\u4f7f\u7528\u4f60\u672c\u5730\u7684 SSH Key\uff1a<\/p>\n<pre>\nLocal ---(SSH)---> Server1 ---(SSH)---> Server2\n<\/pre>\n<p>\u90a3\u8981\u600e\u9ebc\u4f7f\u7528:<\/p>\n<p>\u9996\u5148\u9700\u8981\u5c07\u8981 forwarding \u7684 private key \u52a0\u5230\u6e05\u55ae\u88e1\u9762:<\/p>\n<pre>\nssh-add\n<\/pre>\n<p>\u7528<\/p>\n<pre>ssh-add -L<\/pre>\n<p>\u53ef\u4ee5\u6aa2\u67e5\u9019\u500b\u6e05\u55ae\u3002\u63a5\u8457\uff1a<\/p>\n<p>\u65b9\u6cd5\u4e00\uff1a\u6bcf\u6b21\u8981 Local \u9023\u4e0a Server \u6642\uff0c\u52a0\u4e0a -A \u53c3\u6578\uff1a<\/p>\n<pre>\nssh -A user@{you server1 ip}\n<\/pre>\n<p>\u65b9\u6cd5\u4e8c\uff1a\u4fee\u6539 ~\/.ssh\/config \u8a2d\u5b9a\uff0c\u52a0\u4e0a ForwardAgent yes\uff0c\u9019\u6a23\u5c31\u4e0d\u9700\u8981\u6bcf\u6b21\u9023\u90fd\u52a0\u4e0a -A \u53c3\u6578\u3002\u4f8b\u5982<\/p>\n<pre>\nHost server1\n  HostName 106.187.36.122\n  ForwardAgent yes\n<\/pre>\n<p>\u5be6\u52d9\u4e0a\u6709\u4ec0\u9ebc\u61c9\u7528\u5462? \u9019\u88e1\u8209\u5169\u500b\u5e38\u7528\u7684\u4f8b\u5b50\uff1a<\/p>\n<h3>Bastion Host<\/h3>\n<p>\u5728 AWS \u7684\u67b6\u69cb\u8ab2\u4e2d\uff0c\u6bcf\u6b21\u8b1b <a href=\"http:\/\/aws.amazon.com\/vpc\/\">VPC<\/a> \u5c31\u6703\u63d0\u5230 <a href=\"http:\/\/en.wikipedia.org\/wiki\/Bastion_host\">Bastion host<\/a> \u7684\u6982\u5ff5\uff0c\u4e5f\u5c31\u662f\u6574\u7d44\u5167\u90e8\u7db2\u8def\u53ea\u958b\u653e\u4e00\u53f0 server \u53ef\u4ee5\u5f9e\u5916\u90e8\u505a SSH \u9023\u7dda\uff0c\u5982\u679c\u9700\u8981 SSH \u9023\u7dda\u5176\u4ed6\u6a5f\u5668\uff0c\u90fd\u5fc5\u9808\u900f\u904e\u9019\u4e00\u53f0 Bastion host \u8f49\u904e\u53bb\u3002\u9019\u6a23\u505a\u7684\u76ee\u7684\u7576\u7136\u662f\u70ba\u4e86\u5b89\u5168\u6027\uff0c\u6211\u5011\u53ef\u4ee5\u7279\u5225\u52a0\u5f37\u9019\u4e00\u53f0 Bastion host \u7684\u5b89\u5168\uff0c\u4f8b\u5982\u9396\u5916\u90e8 IP \u6216\u662f\u88dd <a href=\"http:\/\/en.wikipedia.org\/wiki\/Security-Enhanced_Linux\">SELinux<\/a> \u7b49\u7b49\uff0c\u9019\u4e00\u53f0\u7684\u7528\u9014\u5c31\u5c08\u9580\u53ea\u505a SSH \u9023\u7dda\uff0c\u7562\u7adf\u8d8a\u7c21\u55ae\u8d8a\u5bb9\u6613\u9632\u8b77\uff0c\u66f4\u7d30\u7bc0\u7684 OS \u9632\u8b77\u539f\u5247\u53ef\u4ee5\u53c3\u8003 <a href=\"http:\/\/etutorials.org\/Linux+systems\/secure+linux-based+servers\/Chapter+3.+Hardening+Linux\/Section+3.1.+OS+Hardening+Principles\/\">OS Hardening Principles<\/a>\u3002<\/p>\n<p>\u65e2\u7136 SSH \u9023\u7dda\u90fd\u5fc5\u9808\u900f\u904e\u9019\u53f0 <a href=\"http:\/\/en.wikipedia.org\/wiki\/Bastion_host\">Bastion host<\/a>\uff0c\u90a3\u9ebc SSH agent forwarding \u9019\u62db\u5c31\u5f88\u597d\u7528\u4e86\uff0c\u5c31\u4e0d\u9700\u8981\u3001\u4e5f\u4e0d\u61c9\u8a72\u628a private key \u653e\u5230 Bastion host \u4e0a\u9762\u3002<\/p>\n<h3>Git Deployment<\/h3>\n<p>\u5982\u679c\u4f60\u6709\u7528 Git \u7248\u672c\u63a7\u5236\u7cfb\u7d71\u7684\u8a71\uff0c\u4f60\u7684\u61c9\u7528\u7a0b\u5f0f\u4f48\u7f72\u4e5f\u5f88\u53ef\u80fd\u9700\u8981\u5728 Server \u4e0a\u628a Source Code \u5f9e repository \u62c9\u4e0b\u4f86\uff0c\u9019\u6642\u5019\u5c31\u6703\u9700\u8981 SSH \u7684\u6b0a\u9650\u3002<\/p>\n<p>\u4ee5\u524d\u5c0f\u6642\u5019\u4e0d\u61c2\u4e8b\uff0c\u7e3d\u662f\u5728 Server \u4e0a\u751f\u51fa\u4e00\u7d44\u90e8\u7f72\u5c08\u7528\u7684 SSH key pair\uff0c\u7136\u5f8c\u5728 Github \u4e0a\u8a2d\u5b9a\u9019\u7d44 key \u53ef\u4ee5\u8b80\u53d6 repository\u3002\u5f8c\u4f86\u767c\u73fe\u9019\u5b8c\u5168\u662f\u591a\u9918\u53c8\u589e\u52a0\u5b89\u5168\u98a8\u96aa\u3002\u65e2\u7136\u6709\u6b0a\u9650\u4f48\u7f72\uff0c\u90a3\u9ebc\u4e5f\u5c31\u8868\u793a\u4f60\u61c9\u8a72\u5c31\u6709\u6b0a\u9650\u53ef\u4ee5\u8b80\u53d6 source code\uff0c\u90a3\u5c31\u7528\u4f60\u81ea\u5df1\u7684 SSH key \u5c31\u597d\u5566\uff0c\u5c31\u4e0d\u9700\u8981\u5728 server \u4e0a\u64fa\u4e00\u7d44 SSH key pair \u4e86\u3002<\/p>\n<p>\u5982\u679c\u662f\u7528 Ruby \u7684 <a href=\"http:\/\/capistranorb.com\/\">capistrano<\/a> \u505a\u90e8\u7f72\u7684\u8a71\uff0c\u53ea\u8981\u8a2d\u5b9a\u4e00\u4e0b\u5c31\u53ef\u4ee5\u4e86\uff1a<\/p>\n<pre>\n<code>\nset :ssh_options, {\n  forward_agent: true\n}\n<\/code>\n<\/pre>\n<p>\u9019\u6a23\u5728\u4f48\u7f72\u7a0b\u5e8f\u4e2d\u5c31\u6703\u7528\u5230\u4f60\u81ea\u5df1\u7684 SSH key \u53bb Github \u62c9 source code \u4e86\u3002<\/p>\n<h3>\u53c3\u8003\u8cc7\u6599<\/h3>\n<ul>\n<li><a href=\"http:\/\/blogs.aws.amazon.com\/security\/post\/Tx3N8GFK85UN1G6\/Securely-connect-to-Linux-instances-running-in-a-private-Amazon-VPC\">Securely connect to Linux instances running in a private Amazon VPC<\/a><\/li>\n<li><a href=\"https:\/\/developer.github.com\/guides\/using-ssh-agent-forwarding\/\">Using SSH agent forwarding<\/a><\/li>\n<li><a href=\"http:\/\/unixwiz.net\/techtips\/ssh-agent-forwarding.html\">An Illustrated Guide to SSH Agent Forwarding<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>SSH agent forwarding \u53ef\u4ee5\u8b93\u672c\u5730\u7684 SSH Key \u5728\u9060\u7aef Server \u4e0a\u9032\u884c\u8f49\u9001\uff0c\u4e5f\u5c31 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/ihower.tw\/blog\/7837-ssh-agent-forwarding\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008SSH agent forwarding \u7684\u61c9\u7528\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[68,48],"tags":[],"class_list":["post-7837","post","type-post","status-publish","format-standard","hentry","category-devops","category-git","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1q6tG-22p","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/7837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/comments?post=7837"}],"version-history":[{"count":20,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/7837\/revisions"}],"predecessor-version":[{"id":8199,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/7837\/revisions\/8199"}],"wp:attachment":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/media?parent=7837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/categories?post=7837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/tags?post=7837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}