{"id":202837,"date":"2020-10-22T10:21:20","date_gmt":"2020-10-22T02:21:20","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=202837"},"modified":"2020-10-14T10:23:25","modified_gmt":"2020-10-14T02:23:25","slug":"ca-ssh","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/ca-ssh.html","title":{"rendered":"\u57fa\u4e8eCA\u7b7e\u540d\u7684\u7528\u6237\u516c\u94a5\u7ba1\u7406"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u901a\u8fc7CA\u7b7e\u540d\u7528\u6237\u516c\u94a5\u7684\u8bc1\u4e66\u7edf\u4e00\u7ba1\u7406\u65b9\u6cd5\u3002\u901a\u8fc7\u8be5\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u57fa\u4e8e\u89d2\u8272\u901a\u8fc7ssh\u7ba1\u7406\u5bf9\u670d\u52a1\u5668\u7684\u8bbf\u95ee\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4e3a\u4e86\u5b89\u5168\u4fbf\u6377\u7684\u7ba1\u7406\u548c\u7ef4\u62a4\u670d\u52a1\u5668\uff0c\u7981\u6b62SSH\u5bc6\u7801\u767b\u9646\uff0c\u5e76\u7528\u8bc1\u4e66\u8ba4\u8bc1\u662f\u6bd4\u8f83\u597d\u7684\u9009\u62e9\u3002\u5176\u65b9\u6cd5\u662f\u7528\u6237\u751f\u6210\u5bc6\u94a5\u5bf9\uff0c\u5176\u79c1\u94a5\u4e25\u683c\u4fdd\u7ba1\u4e0d\u6cc4\u9732\uff0c\u5c06\u516c\u94a5\u6dfb\u52a0\u5230\u670d\u52a1\u5668\u4e0a\u7528\u6237\u5bf9\u5e94\u7684authorized_keys\u6587\u4ef6\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u7528\u8bc1\u4e66\u65b9\u5f0f\u8fdb\u884c\u767b\u9646\uff0c\u5728\u8bc1\u4e66\u751f\u6210\u7684\u65f6\u5019\uff0c\u4e5f\u53ef\u4ee5\u5bf9\u8bc1\u4e66\u6dfb\u52a0\u5bc6\u7801\uff0c\u9632\u6b62\u79c1\u94a5\u88ab\u76d7\u7528\u3002<\/p>\n

\"\"<\/p>\n

\u8fd9\u79cd\u65b9\u5f0f\u5f88\u65b9\u4fbf\uff0c\u4f46\u662f\u5b58\u5728\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u5f53\u670d\u52a1\u5668\u6bd4\u8f83\u591a\u7684\u65f6\u5019\uff0c\u5bf9\u670d\u52a1\u5668\u4e0a\u516c\u94a5\u7684\u7ba1\u7406\u5c31\u4f1a\u6bd4\u8f83\u9ebb\u70e6\uff0c\u5bb9\u6613\u5f53\u4eba\u5458\u53d1\u751f\u53d8\u5316\u65f6\u5019\uff0c\u5bb9\u6613\u6e05\u7406\u9057\u6f0f\uff0c\u4ece\u800c\u5bfc\u81f4\u5b89\u5168\u9690\u60a3\u3002\u672c\u6587\u6211\u4eec\u4ecb\u7ecd\u4e00\u79cd\u901a\u8fc7\u4e2d\u5fc3CA\u7edf\u4e00\u7b7e\u53d1\u8bc1\u4e66\u7ba1\u7406SSH\u8bc1\u4e66\u7684\u65b9\u6cd5\u3002<\/p>\n

\u6982\u8ff0<\/strong><\/div>\n

\u4e3a\u4e86\u89e3\u51b3\u7edf\u4e00\u7ba1\u7406\u7684\u95ee\u9898\uff0c\u5f15\u5165CA\u6765\u7edf\u4e00\u7ba1\u7406SSH\u7684\u8ba4\u8bc1\u3002\u7528\u6237\u4ecd\u7136\u9700\u8981\u751f\u6210\u4e00\u4e2a\u516c\u94a5\u548c\u79c1\u94a5\u5bf9\u8bc1\u4e66\u3002\u4f46\u662f\uff0c\u8ba4\u8bc1\u4e0d\u662f\u901a\u8fc7\u5c06\u7528\u6237\u516c\u94a5\u6dfb\u52a0\u670d\u52a1\u5668\u6765\u5b8c\u6210\uff0c\u4f7f\u7528\u8bc1\u4e66\u9881\u53d1\u673a\u6784(CA)\u5bc6\u94a5\u5bf9\u7528\u6237\u516c\u94a5\u8fdb\u884c\u7b7e\u540d\u3002\u7b7e\u540d\u8fc7\u7a0b\u4ec5\u751f\u6210\u4e86\u7b2c\u4e09\u4e2a\u8bc1\u4e66\u6587\u4ef6\uff0c\u7528\u6237\u901a\u8fc7\u8be5\u7b7e\u53d1\u8bc1\u4e66\u548c\u81ea\u5df1\u539f\u6709\u7684\u8bc1\u4e66\u5bf9\u5c31\u80fd\u5b8c\u6210\u767b\u9646\u3002<\/p>\n

\u670d\u52a1\u5668\u4e0a\uff0c\u53ea\u9700\u914d\u7f6eSSH\u5bf9CA\u7684\u516c\u94a5\u8ba4\u8bc1\uff0c\u670d\u52a1\u5668\u901a\u8fc7\u68c0\u6d4b\u7528\u6237\u8bc1\u4e66\u662f\u5426\u901a\u8fc7CA\u7b7e\u53d1\uff0c\u6765\u5b8c\u6210\u8ba4\u8bc1\u8fc7\u7a0b\u3002<\/p>\n

\"\"<\/p>\n

\u5177\u4f53\u505a\u6cd5<\/strong><\/div>\n
\u521b\u5efaCA<\/strong><\/span><\/div>\n

\u7528\u6237\u751f\u6210\u4e00\u4e2a\u8bc1\u4e66\u9881\u53d1\u673a\u6784CA\u79c1\u94a5\u5bf9\uff0c\u5e76\u4fdd\u8bc1\u79c1\u94a5\u7684\u79c1\u94a5\u5b89\u5168\uff1a<\/p>\n

umask 77 # \u4fee\u6539\u63a9\u7801\uff0c\u4fdd\u8bc1\u6b64\u540e\u751f\u6210\u76ee\u5f55\u548c\u6587\u4ef6\u7684\u6743\u9650<\/p>\n

\r\nmkdir ~\/CC-ca && cd ~\/CC-ca \r\nssh-keygen -C CA -f ca -b 4096 \r\n<\/pre>\n

\u751f\u6210\u65f6\u5019\uff0c\u7ed9\u8bc1\u4e66\u6dfb\u52a0\u4e00\u4e2a\u5bc6\u7801\uff0c\u4ee5\u9632\u6b62\u6cc4\u9732\u3002<\/p>\n

\u914d\u7f6eCA\u516c\u94a5\u8ba4\u8bc1<\/strong><\/span><\/div>\n

\u7136\u540e\u5728\u670d\u52a1\u5668\u4e0a\uff0c\u6307\u5b9a\u5141\u8bb8\u7531CA\u7b7e\u540d\u7684\u6240\u6709\u7528\u6237\u8bbf\u95ee\u8be5\u670d\u52a1\u5668\uff1a<\/p>\n

\u5c06CA\u7684\u516c\u94a5\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u4e0a\uff0c\u4f8b\u5982\u5728\/etc\/ssh\/ca.pub<\/p>\n

\u5728\/etc\/ssh\/sshd_config\u6dfb\u52a0\u4e0b\u9762\u7684\u884c\uff0c\u914d\u7f6eCA\u7b7e\u53d1\u7684\u8bc1\u4e66\u7684\u4fe1\u4efb\uff1a<\/p>\n

\r\nTrustedUserCAKeys \/etc\/ssh\/ca.pub \r\n<\/pre>\n

\u91cd\u542fsshd\u670d\u52a1\uff1a<\/p>\n

\r\nservice sshd reload\r\n<\/pre>\n
CA\u7b7e\u53d1\u7528\u6237\u8bc1\u4e66<\/strong><\/span><\/div>\n

\u7528\u6237\u4f7f\u7528ssh-keygen\u751f\u6210\u8bc1\u4e66\uff0c\u5e76\u4e14\u628a\u516c\u94a5\u53d1\u7ed9CA\u4e2d\u5fc3\uff0cCA\u4e2d\u5fc3\u7528\u79c1\u94a5\u5bf9\u8be5\u8bc1\u4e66\u6dfb\u52a0\u7b7e\u540d\uff1a<\/p>\n

\r\nssh-keygen -s ca -I USER_ID -V +12w -z 1 id_ecdsa.pub \r\n<\/pre>\n

\u547d\u4ee4\u884c\u8bf4\u660e\uff1a<\/p>\n

-s ca \u60f3\u4f7f\u7528CA\u8fdb\u884c\u7b7e\u540d<\/p>\n

-I USER_ID -\u7528\u6237ID\/\u7528\u6237\u540d<\/p>\n

-V +12w -\u8bc1\u4e66\u8fc7\u671f\u524d\u7684\u65f6\u95f4\uff0c\u8be5\u4f8b\u5b50\u4e2d\u8bc1\u4e66\u6709\u6548\u671f\u4e3a12\u5468<\/p>\n

-z 1 \u8bbe\u7f6e\u8bc1\u4e66\u7684\u5e8f\u5217\u53f7\uff0c\u53ef\u4ee5\u7528\u8bc1\u4e66\u7684\u5e8f\u5217\u53f7\u6765\u6ce8\u9500\u8bc1\u4e66\u3002<\/p>\n

id_ecdsa.pub\uff1a\u9700\u8981\u7b7e\u540d\u7684\u7528\u6237\u516c\u94a5<\/p>\n

\u751f\u6210\u8bc1\u4e66id_ecdsa-cert.pub\uff0c\u8be5\u8bc1\u4e66\u9700\u8981\u53d1\u9001\u7ed9\u5f00\u53d1\u4eba\u5458\uff0c\u7528\u6237\u5c06\u5176\u653e\u5165~\/.ssh\u6587\u4ef6\u5939\u3002<\/p>\n

\u6dfb\u52a0\u89d2\u8272<\/strong><\/span><\/div>\n

\u4e0a\u9762\u5c31\u53ef\u4ee5\u5b8c\u6210\u4e86\u8bc1\u4e66\u7684CA\u7b7e\u540d\u548c\u7edf\u4e00\u8ba4\u8bc1\u3002\u4f46\u662f\u8fd8\u6709\u4e00\u4e2a\u95ee\u9898\uff0c\u53ef\u80fd\u7528\u6237\u4e5f\u9700\u8981\u5206\u7c7b\uff0c\u4e0d\u540c\u7684\u56e2\u961f\u548c\u89d2\u8272\u7684\uff0c\u9700\u8981\u6709\u4e0d\u540c\u7684\u8bbf\u95ee\u6743\u9650\u3002\u5b9e\u9645\u4e0a\uff0c\u53ef\u4ee5\u5728\u7b7e\u540d\u8fc7\u7a0b\u4e2d\u6dfb\u52a0\u89d2\u8272\uff0c\u7528\u6765\u6307\u5b9a\u5141\u8bb8\u670d\u52a1\u5668\u7684\u8bbf\u95ee\u6743\u9650\u3002\u65b0\u6dfb\u52a0\u7528\u6237\u65f6\u5019\uff0c\u5373\u53ef\u4f7f\u4ed6\u4eec\u53ef\u4ee5\u8bbf\u95ee\u6240\u6709\u76f8\u5173\u670d\u52a1\u5668\uff0c\u800c\u65e0\u9700\u5728\u8fd9\u4e9b\u670d\u52a1\u5668\u4e0a\u6dfb\u52a0\u4efb\u4f55\u5185\u5bb9\u3002<\/p>\n

\"\"<\/p>\n

\u670d\u52a1\u5668\u4e0a\u914d\u7f6e\u89d2\u8272\u4fe1\u606f<\/strong><\/span><\/div>\n

\u521b\u5efa\u7528\u4e8e\u914d\u7f6e\u8bbf\u95ee\u6743\u9650\u7684\u6587\u4ef6\u5939\uff1a<\/p>\n

\r\nmkdir \/etc\/ssh\/auth_principals\r\n<\/pre>\n

\u5728\u8be5\u6587\u4ef6\u5939\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u670d\u52a1\u5668\u7528\u6237\u540d\u521b\u5efa\u6587\u4ef6\uff0c\u8be5\u7528\u6237\u53ef\u4ee5\u767b\u5f55\u3002\u4f8b\u5982\uff0c\u8981\u6388\u4e88\u5bf9\u67d0\u4e9b\u89d2\u8272\u7684root\u7528\u6237\u8bbf\u95ee\u6743\u9650\uff0c\u8bf7\u6dfb\u52a0\u6587\u4ef6\/etc\/ssh\/auth_principals\/root\u3002<\/p>\n

\u5728\/etc\/ssh\/auth_principals\/root\u6587\u4ef6\u4e2d\uff0c\u914d\u7f6e\u53ef\u4ee5\u4ee5root\u7528\u6237\u8eab\u4efd\u767b\u5f55\u7684\u89d2\u8272\uff0c\u6bcf\u884c\u4e00\u4e2a\u89d2\u8272\uff0c\u6bd4\u5982<\/p>\n

\r\nadmin_dev\r\nroot_op\r\nROLE1\r\n<\/pre>\n

\u5728\u670d\u52a1\u5668\u4e0aSSHD\u914d\u7f6e\u6587\u4ef6\/etc\/ssh\/sshd_config\uff0c\u6dfb\u52a0\u5bf9\u89d2\u8272\u7684\u8ba4\u8bc1\uff1a<\/p>\n

\r\nAuthorizedPrincipalsFile \/etc\/ssh\/auth_principals\/%u \r\n<\/pre>\n

\u7136\u540e\u91cd\u65b0\u52a0\u8f7dsshd\u670d\u52a1<\/p>\n

\r\nservice sshd reload\r\n<\/pre>\n
CA\u7b7e\u53d1\u5e26\u89d2\u8272\u7684\u7528\u6237\u8bc1\u4e66<\/strong><\/span><\/div>\n

\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e0b\u547d\u4ee4\u884c\uff0c\u7b7e\u53d1\u5e26\u89d2\u8272\u7684\u8bc1\u4e66\uff1a<\/p>\n

\r\nssh-keygen -s ca -I USER_ID -n ROLE1,ROLE2 -V +12w -z 2 id_ecdsa.pub \r\n<\/pre>\n

\u4e0e\u4ee5\u524d\u547d\u4ee4\u884c\u4e00\u6837\uff0c\u591a\u589e\u52a0\u4e86-n ROLE1,ROLE2\u6807\u5fd7\u3002<\/p>\n

\u73b0\u5728\uff0c\u8be5\u7528\u6237\u53ef\u4ee5\u767b\u5f55\u5230auth_principals\u6587\u4ef6\u914d\u7f6e\u4e86ROLE1\u6216ROLE2\u89d2\u8272\u7684\u670d\u52a1\u5668\u3002<\/p>\n

\u6ce8\u9500\u8bc1\u4e66<\/strong><\/span><\/div>\n

\u524d\u9762\u8bf4\u4e86\uff0c\u53ef\u4ee5\u5bf9\u7528\u6237\u8bc1\u4e66\u8fdb\u884c\u6ce8\u9500\u3002\u6ce8\u9500\u7528\u6237\u9700\u8981\u7528\u7684\u7528\u6237\u7684\u5e8f\u5217\u53f7\u3002\u5efa\u8bae\u540c\u610f\u7ef4\u62a4\u4e00\u4e2a\u7528\u6237\u5e8f\u5217\u53f7\u7684\u5217\u8868\uff0c\u6216\u5efa\u7acb\u6570\u636e\u5e93\u3002<\/p>\n

\u6ce8\u9500\u8bc1\u4e66\u6587\u4ef6<\/strong><\/span><\/div>\n

\u901a\u8fc7\u4e0b\u9762\u7684\u547d\u4ee4\u751f\u6210\u4e00\u4e2a\u6ce8\u9500\u8bc1\u4e66\u6587\u4ef6<\/p>\n

\r\nssh-keygen -k -f revoked-keys -u -s ca list-to-revoke \r\n<\/pre>\n

\u5f53\u5df2\u7ecf\u6709\u4e00\u4e2arevoked-keys\u5217\u8868\u5e76\u60f3\u8981\u66f4\u65b0\u8bc1\u4e66\u65f6\u5019(-u\u6807\u5fd7)\u3002<\/p>\n

\u5728list-to-revoke\u6587\u4ef6\u5185\u5bb9\u7531\u7528\u6237\u540d(IDS)\u6216\u5e8f\u5217\u53f7(\u7684-z\u751f\u6210\u671f\u95f4\u6807\u5fd7)\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n

\r\nserial: 1\r\nid: test.user\r\n<\/pre>\n

\u8fd9\u5c06\u64a4\u6d88\u5bf9\u5e8f\u5217\u53f7\u4e3a1\u7684\u8bc1\u4e66\u548c\u6240\u6709ID\u4e3atest.user\u7684\u8bc1\u4e66\u7684\u8bbf\u95ee\u6743\u9650\u3002<\/p>\n

\u670d\u52a1\u5668\u914d\u7f6e\u6ce8\u9500<\/strong><\/span><\/div>\n

\u4e3a\u4e86\u4f7f\u670d\u52a1\u5668\u5b8c\u6210\u5bf9\u64a4\u9500\u5bc6\u94a5\u914d\u7f6e\uff0c\u9700\u8981\u5c06\u751f\u6210\u7684\/\u66f4\u65b0\u7684revoked keys\u6587\u4ef6\u6dfb\u52a0\u5230\/etc\/ssh\/revoked-keys\u5e76\u5728\/etc\/ssh\/sshd_config\u914d\u7f6e\uff1a<\/p>\n

\r\nRevokedKeys \/etc\/ssh\/revoked-keys \r\n<\/pre>\n

\u6ce8\u610f\uff1a\u8bf7\u786e\u4fdd\u8be5revoked-keys\u6587\u4ef6\u4e3a\u53ef\u8bbf\u95ee\u4e14\u53ef\u8bfb\uff0c\u5426\u5219\u4f1a\u5bfc\u81f4\u4efb\u4f55\u7528\u6237\u90fd\u4e0d\u80fd\u8bbf\u95ee\u3002<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

\u672c\u6587\u6211\u4eec\u4ecb\u7ecd\u4e86\u4e00\u4e2a\u901a\u8fc7CA\u7b7e\u540d\u7528\u6237\u516c\u94a5\u7684\u8bc1\u4e66\u7edf\u4e00\u7ba1\u7406\u65b9\u6cd5\u3002\u901a\u8fc7\u8be5\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u57fa\u4e8e\u89d2\u8272\u901a\u8fc7ssh\u7ba1\u7406\u5bf9\u670d\u52a1\u5668\u7684\u8bbf\u95ee\u3002\u53ea\u9700\u8981\u914d\u7f6e\u670d\u52a1\u5668\u4e00\u6b21(\u5141\u8bb8\u54ea\u4e9b\u89d2\u8272\u8bbf\u95ee\u670d\u52a1\u5668)\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u7528\u6237\uff0c\u53ea\u9700\u8981\u751f\u6210\u4e00\u4e2a\u7b7e\u540d\u8bc1\u4e66\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u6309\u89d2\u8272\u767b\u9646\u6240\u6709\u76f8\u5173\u673a\u5668\u7684\u65b9\u6cd5\u3002\u4e5f\u53ef\u4ee5\u65b9\u4fbf\u6ce8\u9500\u7528\u6237\u7684\u8bc1\u4e66\uff0c\u4ece\u800c\u9650\u5236\u7528\u6237\u7684\u8bbf\u95ee\u3002\u7531\u4e8e\u6bcf\u4e2a\u8bc1\u4e66\u7b7e\u540d\u90fd\u8981\u6709\u6548\u6027\u9650\u5236\uff0c\u5373\u4f7f\u672a\u80fd\u53ca\u65f6\u6ce8\u9500\u7528\u6237\u6743\u9650\uff0c\u4e5f\u53ef\u4ee5\u5728\u8d85\u8fc7\u6709\u6548\u671f\u540e\u81ea\u52a8\u6ce8\u9500\uff0c\u4ece\u800c\u4fdd\u8bc1\u4e86\u5b89\u5168\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4e3a\u4e86\u5b89\u5168\u4fbf\u6377\u7684\u7ba1\u7406\u548c\u7ef4\u62a4\u670d\u52a1\u5668\uff0c\u7981\u6b62SSH\u5bc6\u7801\u767b\u9646\uff0c\u5e76\u7528\u8bc1\u4e66\u8ba4\u8bc1\u662f\u6bd4\u8f83\u597d\u7684\u9009\u62e9\u3002\u5176\u65b9\u6cd5\u662f\u7528\u6237\u751f\u6210\u5bc6\u94a5\u5bf9\uff0c\u5176\u79c1\u94a5 […]<\/p>\n","protected":false},"author":668,"featured_media":202843,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-202837","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/202837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=202837"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/202837\/revisions"}],"predecessor-version":[{"id":202862,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/202837\/revisions\/202862"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/202843"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=202837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=202837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=202837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}