{"id":46141,"date":"2025-07-30T02:32:45","date_gmt":"2025-07-29T18:32:45","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/46141.html"},"modified":"2025-07-30T02:32:45","modified_gmt":"2025-07-29T18:32:45","slug":"%e3%80%90%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%8e%e9%83%a8%e7%bd%b2-02%e3%80%91ssh%e8%bf%9c%e7%a8%8b%e7%ae%a1%e7%90%86%e7%a5%9e%e5%99%a8%ef%bc%9a%e5%91%8a%e5%88%ab%e5%af%86%e7%a0%81%ef%bc%8c%e6%8b%a5","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/46141.html","title":{"rendered":"\u3010\u670d\u52a1\u5668\u4e0e\u90e8\u7f72 02\u3011SSH\u8fdc\u7a0b\u7ba1\u7406\u795e\u5668\uff1a\u544a\u522b\u5bc6\u7801\uff0c\u62e5\u62b1\u5b89\u5168\u9ad8\u6548\u7684\u670d\u52a1\u5668\u8fde\u63a5"},"content":{"rendered":"<h2>\u3010\u670d\u52a1\u5668\u4e0e\u90e8\u7f72 02\u3011SSH\u8fdc\u7a0b\u7ba1\u7406\u795e\u5668&#xff1a;\u544a\u522b\u5bc6\u7801&#xff0c;\u62e5\u62b1\u5b89\u5168\u9ad8\u6548\u7684\u670d\u52a1\u5668\u8fde\u63a5<\/h2>\n<p>\u5173\u952e\u8bcd&#xff1a; SSH\u8fde\u63a5\u3001\u8fdc\u7a0b\u670d\u52a1\u5668\u7ba1\u7406\u3001\u5bc6\u94a5\u8ba4\u8bc1\u3001\u6587\u4ef6\u4f20\u8f93\u3001\u670d\u52a1\u5668\u5b89\u5168\u3001SCP\u3001SFTP\u3001\u7aef\u53e3\u8f6c\u53d1<\/p>\n<p>\u6458\u8981&#xff1a; \u672c\u6587\u901a\u8fc7\u8d39\u66fc\u5b66\u4e60\u6cd5&#xff0c;\u4ece\u96f6\u5f00\u59cb\u8be6\u89e3SSH\u8fdc\u7a0b\u670d\u52a1\u5668\u7ba1\u7406\u7684\u6838\u5fc3\u6280\u672f\u3002\u4ece\u57fa\u7840\u8fde\u63a5\u5230\u9ad8\u7ea7\u914d\u7f6e&#xff0c;\u4ece\u5bc6\u7801\u8ba4\u8bc1\u5230\u5bc6\u94a5\u7ba1\u7406&#xff0c;\u4ece\u6587\u4ef6\u4f20\u8f93\u5230\u7aef\u53e3\u8f6c\u53d1&#xff0c;\u5168\u9762\u638c\u63e1SSH\u8fd9\u4e2a\u670d\u52a1\u5668\u7ba1\u7406\u795e\u5668\u3002\u901a\u8fc7\u751f\u52a8\u7684\u7c7b\u6bd4\u548c\u5b9e\u9645\u6848\u4f8b&#xff0c;\u8ba9\u4f60\u5f7b\u5e95\u7406\u89e3SSH\u7684\u5de5\u4f5c\u539f\u7406&#xff0c;\u5e76\u5b66\u4f1a\u5728Python\u9879\u76ee\u90e8\u7f72\u4e2d\u9ad8\u6548\u4f7f\u7528SSH\u8fdb\u884c\u8fdc\u7a0b\u7ba1\u7406\u3002<\/p>\n<h3>\u5f15\u8a00&#xff1a;SSH\u4e3a\u4ec0\u4e48\u662f\u670d\u52a1\u5668\u7ba1\u7406\u7684\u5fc5\u5907\u5de5\u5177&#xff1f;<\/h3>\n<p>\u8fd8\u8bb0\u5f97\u7b2c\u4e00\u6b21\u9700\u8981\u8fde\u63a5\u8fdc\u7a0b\u670d\u52a1\u5668\u65f6\u7684\u7d27\u5f20\u611f\u5417&#xff1f;\u9762\u5bf9\u9ed1\u5c4f\u767d\u5b57\u7684\u7ec8\u7aef&#xff0c;\u8f93\u5165\u4e00\u957f\u4e32IP\u5730\u5740\u548c\u5bc6\u7801&#xff0c;\u751f\u6015\u4e00\u4e2a\u5b57\u7b26\u9519\u8bef\u5c31\u8fde\u4e0d\u4e0a\u670d\u52a1\u5668\u3002\u66f4\u7cdf\u7cd5\u7684\u662f&#xff0c;\u6bcf\u6b21\u8fde\u63a5\u90fd\u8981\u91cd\u65b0\u8f93\u5165\u5bc6\u7801&#xff0c;\u65e2\u7e41\u7410\u53c8\u4e0d\u5b89\u5168\u3002<\/p>\n<p>\u5982\u679c\u6211\u544a\u8bc9\u4f60&#xff0c;\u6709\u4e00\u79cd\u65b9\u6cd5\u53ef\u4ee5&#xff1a;<\/p>\n<ul>\n<li>\u4e00\u79d2\u8fde\u63a5&#xff1a;\u65e0\u9700\u8f93\u5165\u5bc6\u7801&#xff0c;\u4e00\u6761\u547d\u4ee4\u76f4\u8fbe\u670d\u52a1\u5668<\/li>\n<li>\u5b89\u5168\u4f20\u8f93&#xff1a;\u6240\u6709\u6570\u636e\u90fd\u7ecf\u8fc7\u519b\u7528\u7ea7\u52a0\u5bc6<\/li>\n<li>\u6279\u91cf\u7ba1\u7406&#xff1a;\u540c\u65f6\u7ba1\u7406\u591a\u53f0\u670d\u52a1\u5668\u5982\u540c\u7ba1\u7406\u4e00\u53f0<\/li>\n<li>\u6587\u4ef6\u540c\u6b65&#xff1a;\u672c\u5730\u548c\u670d\u52a1\u5668\u6587\u4ef6\u5b9e\u65f6\u540c\u6b65<\/li>\n<\/ul>\n<p>\u8fd9\u5c31\u662fSSH&#xff08;Secure Shell&#xff09;\u7684\u9b45\u529b&#xff01;\u5b83\u4e0d\u4ec5\u4ec5\u662f\u4e00\u4e2a\u8fde\u63a5\u5de5\u5177&#xff0c;\u66f4\u662f\u73b0\u4ee3\u670d\u52a1\u5668\u7ba1\u7406\u7684\u57fa\u77f3\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729183243-688913cbf1fe9.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>\u7b2c\u4e00\u6b65&#xff1a;\u7406\u89e3SSH &#8211; \u7f51\u7edc\u4e16\u754c\u7684\u5b89\u5168\u901a\u9053<\/h3>\n<h4>SSH\u662f\u4ec0\u4e48&#xff1f;\u7528\u751f\u6d3b\u4e2d\u7684\u4f8b\u5b50\u6765\u7406\u89e3<\/h4>\n<p>\u60f3\u8c61SSH\u5c31\u50cf\u662f\u4f60\u5bb6\u548c\u670b\u53cb\u5bb6\u4e4b\u95f4\u7684\u4e00\u6761\u5730\u4e0b\u5b89\u5168\u901a\u9053&#xff1a;<\/p>\n<li>\u666e\u901a\u7f51\u7edc\u8fde\u63a5\u5c31\u50cf\u5728\u5927\u8857\u4e0a\u558a\u8bdd &#8211; \u6240\u6709\u4eba\u90fd\u80fd\u542c\u5230<\/li>\n<li>SSH\u8fde\u63a5\u5c31\u50cf\u901a\u8fc7\u52a0\u5bc6\u7684\u5730\u4e0b\u901a\u9053\u79c1\u804a &#8211; \u53ea\u6709\u4f60\u548c\u670b\u53cb\u80fd\u542c\u5230<\/li>\n<p>\u8fd9\u6761&#034;\u5730\u4e0b\u901a\u9053&#034;\u6709\u4e09\u4e2a\u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u52a0\u5bc6\u4f20\u8f93&#xff1a;\u6240\u6709\u6570\u636e\u90fd\u7ecf\u8fc7\u52a0\u5bc6&#xff0c;\u5373\u4f7f\u88ab\u622a\u83b7\u4e5f\u65e0\u6cd5\u7834\u89e3<\/li>\n<li>\u8eab\u4efd\u9a8c\u8bc1&#xff1a;\u786e\u4fdd\u4f60\u8fde\u63a5\u7684\u662f\u6b63\u786e\u7684\u670d\u52a1\u5668<\/li>\n<li>\u5b8c\u6574\u6027\u4fdd\u62a4&#xff1a;\u786e\u4fdd\u6570\u636e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u6ca1\u6709\u88ab\u7be1\u6539<\/li>\n<\/ul>\n<h4>SSH\u7684\u6838\u5fc3\u7ec4\u4ef6<\/h4>\n<p><span class=\"token comment\"># SSH\u8fde\u63a5\u7684\u57fa\u672c\u8bed\u6cd5<\/span><br \/>\n<span class=\"token function\">ssh<\/span> <span class=\"token punctuation\">[<\/span>\u7528\u6237\u540d<span class=\"token punctuation\">]<\/span>&#064;<span class=\"token punctuation\">[<\/span>\u670d\u52a1\u5668\u5730\u5740<span class=\"token punctuation\">]<\/span> <span class=\"token punctuation\">[<\/span>-p \u7aef\u53e3\u53f7<span class=\"token punctuation\">]<\/span><\/p>\n<p><span class=\"token comment\"># \u5b9e\u9645\u4f8b\u5b50<\/span><br \/>\n<span class=\"token function\">ssh<\/span> root&#064;192.168.1.100<br \/>\n<span class=\"token function\">ssh<\/span> ubuntu&#064;myserver.com -p <span class=\"token number\">2222<\/span><\/p>\n<p>SSH\u8fde\u63a5\u5305\u542b\u56db\u4e2a\u8981\u7d20&#xff1a;<\/p>\n<li>\u5ba2\u6237\u7aef&#xff1a;\u4f60\u7684\u7535\u8111&#xff08;\u53d1\u8d77\u8fde\u63a5\u7684\u4e00\u65b9&#xff09;<\/li>\n<li>\u670d\u52a1\u5668&#xff1a;\u8fdc\u7a0b\u670d\u52a1\u5668&#xff08;\u63a5\u53d7\u8fde\u63a5\u7684\u4e00\u65b9&#xff09;<\/li>\n<li>\u7528\u6237\u8ba4\u8bc1&#xff1a;\u8bc1\u660e\u4f60\u662f\u8c01&#xff08;\u5bc6\u7801\u6216\u5bc6\u94a5&#xff09;<\/li>\n<li>\u52a0\u5bc6\u901a\u9053&#xff1a;\u4fdd\u62a4\u6570\u636e\u4f20\u8f93\u7684\u5b89\u5168\u96a7\u9053<\/li>\n<h3>\u7b2c\u4e8c\u6b65&#xff1a;SSH\u8fde\u63a5\u65b9\u5f0f &#8211; \u4ece\u5bc6\u7801\u5230\u5bc6\u94a5\u7684\u8fdb\u5316<\/h3>\n<h4>\u65b9\u5f0f\u4e00&#xff1a;\u5bc6\u7801\u8ba4\u8bc1&#xff08;\u521d\u7ea7\u9636\u6bb5&#xff09;<\/h4>\n<p><span class=\"token comment\"># \u4f7f\u7528\u5bc6\u7801\u8fde\u63a5<\/span><br \/>\n<span class=\"token function\">ssh<\/span> username&#064;server_ip<br \/>\n<span class=\"token comment\"># \u7cfb\u7edf\u4f1a\u63d0\u793a\u8f93\u5165\u5bc6\u7801<\/span><br \/>\nPassword: ********<\/p>\n<p>\u5bc6\u7801\u8ba4\u8bc1\u7684\u95ee\u9898&#xff1a;<\/p>\n<ul>\n<li>\u6bcf\u6b21\u90fd\u8981\u8f93\u5165\u5bc6\u7801&#xff0c;\u6548\u7387\u4f4e<\/li>\n<li>\u5bb9\u6613\u88ab\u66b4\u529b\u7834\u89e3<\/li>\n<li>\u5bc6\u7801\u53ef\u80fd\u5728\u7f51\u7edc\u4f20\u8f93\u4e2d\u88ab\u622a\u83b7<\/li>\n<li>\u65e0\u6cd5\u5b9e\u73b0\u81ea\u52a8\u5316\u811a\u672c<\/li>\n<\/ul>\n<h4>\u65b9\u5f0f\u4e8c&#xff1a;\u5bc6\u94a5\u8ba4\u8bc1&#xff08;\u4e13\u4e1a\u7ea7\u522b&#xff09;<\/h4>\n<p>SSH\u5bc6\u94a5\u8ba4\u8bc1\u5c31\u50cf\u662f\u7ed9\u4f60\u7684\u5bb6\u95e8\u914d\u4e86\u4e00\u628a\u667a\u80fd\u94a5\u5319&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729183244-688913cc1662b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5bc6\u94a5\u8ba4\u8bc1\u7684\u5de5\u4f5c\u539f\u7406&#xff1a;<\/p>\n<li>\u751f\u6210\u5bc6\u94a5\u5bf9&#xff1a;\u521b\u5efa\u4e00\u5bf9\u6570\u5b57\u94a5\u5319&#xff08;\u516c\u94a5\u548c\u79c1\u94a5&#xff09;<\/li>\n<li>\u516c\u94a5\u90e8\u7f72&#xff1a;\u628a\u516c\u94a5\u653e\u5230\u670d\u52a1\u5668\u4e0a&#xff08;\u5c31\u50cf\u628a\u9501\u5b89\u88c5\u5728\u95e8\u4e0a&#xff09;<\/li>\n<li>\u79c1\u94a5\u4fdd\u7ba1&#xff1a;\u79c1\u94a5\u7559\u5728\u672c\u5730&#xff08;\u5c31\u50cf\u94a5\u5319\u968f\u8eab\u643a\u5e26&#xff09;<\/li>\n<li>\u81ea\u52a8\u8ba4\u8bc1&#xff1a;\u8fde\u63a5\u65f6\u81ea\u52a8\u9a8c\u8bc1&#xff0c;\u65e0\u9700\u8f93\u5165\u5bc6\u7801<\/li>\n<h3>\u7b2c\u4e09\u6b65&#xff1a;SSH\u5bc6\u94a5\u7ba1\u7406\u5b9e\u6218<\/h3>\n<h4>\u751f\u6210SSH\u5bc6\u94a5\u5bf9<\/h4>\n<p><span class=\"token comment\"># \u751f\u6210RSA\u5bc6\u94a5\u5bf9&#xff08;\u63a8\u83502048\u4f4d\u6216\u66f4\u9ad8&#xff09;<\/span><br \/>\nssh-keygen -t rsa -b <span class=\"token number\">4096<\/span> -C <span class=\"token string\">&#034;your_email&#064;example.com&#034;<\/span><\/p>\n<p><span class=\"token comment\"># \u751f\u6210ED25519\u5bc6\u94a5\u5bf9&#xff08;\u66f4\u73b0\u4ee3\u7684\u9009\u62e9&#xff09;<\/span><br \/>\nssh-keygen -t ed25519 -C <span class=\"token string\">&#034;your_email&#064;example.com&#034;<\/span><\/p>\n<p><span class=\"token comment\"># \u4ea4\u4e92\u5f0f\u914d\u7f6e<\/span><br \/>\nEnter <span class=\"token function\">file<\/span> <span class=\"token keyword\">in<\/span> <span class=\"token function\">which<\/span> to save the key <span class=\"token punctuation\">(<\/span>\/home\/user\/.ssh\/id_rsa<span class=\"token punctuation\">)<\/span>: <span class=\"token punctuation\">[<\/span>\u56de\u8f66\u4f7f\u7528\u9ed8\u8ba4<span class=\"token punctuation\">]<\/span><br \/>\nEnter passphrase <span class=\"token punctuation\">(<\/span>empty <span class=\"token keyword\">for<\/span> no passphrase<span class=\"token punctuation\">)<\/span>: <span class=\"token punctuation\">[<\/span>\u53ef\u9009&#xff1a;\u8f93\u5165\u5bc6\u7801\u77ed\u8bed<span class=\"token punctuation\">]<\/span><br \/>\nEnter same passphrase again: <span class=\"token punctuation\">[<\/span>\u518d\u6b21\u8f93\u5165\u786e\u8ba4<span class=\"token punctuation\">]<\/span><\/p>\n<p>\u751f\u6210\u7684\u6587\u4ef6&#xff1a;<\/p>\n<ul>\n<li>id_rsa \u6216 id_ed25519&#xff1a;\u79c1\u94a5\u6587\u4ef6&#xff08;\u7edd\u5bf9\u4e0d\u80fd\u6cc4\u9732&#xff09;<\/li>\n<li>id_rsa.pub \u6216 id_ed25519.pub&#xff1a;\u516c\u94a5\u6587\u4ef6&#xff08;\u53ef\u4ee5\u516c\u5f00&#xff09;<\/li>\n<\/ul>\n<h4>\u90e8\u7f72\u516c\u94a5\u5230\u670d\u52a1\u5668<\/h4>\n<p><span class=\"token comment\"># \u65b9\u6cd51&#xff1a;\u4f7f\u7528ssh-copy-id&#xff08;\u63a8\u8350&#xff09;<\/span><br \/>\nssh-copy-id username&#064;server_ip<\/p>\n<p><span class=\"token comment\"># \u65b9\u6cd52&#xff1a;\u624b\u52a8\u590d\u5236<\/span><br \/>\n<span class=\"token function\">cat<\/span> ~\/.ssh\/id_rsa.pub <span class=\"token operator\">|<\/span> <span class=\"token function\">ssh<\/span> username&#064;server_ip <span class=\"token string\">&#034;mkdir -p ~\/.ssh &amp;&amp; cat &gt;&gt; ~\/.ssh\/authorized_keys&#034;<\/span><\/p>\n<p><span class=\"token comment\"># \u65b9\u6cd53&#xff1a;\u4f7f\u7528SCP\u590d\u5236<\/span><br \/>\n<span class=\"token function\">scp<\/span> ~\/.ssh\/id_rsa.pub username&#064;server_ip:~\/.ssh\/authorized_keys<\/p>\n<h4>\u9a8c\u8bc1\u5bc6\u94a5\u8ba4\u8bc1<\/h4>\n<p><span class=\"token comment\"># \u6d4b\u8bd5\u8fde\u63a5&#xff08;\u5e94\u8be5\u65e0\u9700\u8f93\u5165\u5bc6\u7801&#xff09;<\/span><br \/>\n<span class=\"token function\">ssh<\/span> username&#064;server_ip<\/p>\n<p><span class=\"token comment\"># \u5982\u679c\u4ecd\u9700\u8981\u5bc6\u7801&#xff0c;\u68c0\u67e5\u4ee5\u4e0b\u51e0\u70b9&#xff1a;<\/span><br \/>\n<span class=\"token comment\"># 1. \u670d\u52a1\u5668\u4e0a\u7684\u6743\u9650\u8bbe\u7f6e<\/span><br \/>\n<span class=\"token function\">chmod<\/span> <span class=\"token number\">700<\/span> ~\/.ssh<br \/>\n<span class=\"token function\">chmod<\/span> <span class=\"token number\">600<\/span> ~\/.ssh\/authorized_keys<\/p>\n<p><span class=\"token comment\"># 2. \u68c0\u67e5SSH\u670d\u52a1\u914d\u7f6e<\/span><br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">nano<\/span> \/etc\/ssh\/sshd_config<br \/>\n<span class=\"token comment\"># \u786e\u4fdd\u4ee5\u4e0b\u9009\u9879\u6b63\u786e\u8bbe\u7f6e&#xff1a;<\/span><br \/>\nPubkeyAuthentication <span class=\"token function\">yes<\/span><br \/>\nAuthorizedKeysFile .ssh\/authorized_keys<\/p>\n<h3>\u7b2c\u56db\u6b65&#xff1a;SSH\u914d\u7f6e\u6587\u4ef6 &#8211; \u8ba9\u8fde\u63a5\u66f4\u667a\u80fd<\/h3>\n<h4>\u521b\u5efaSSH\u914d\u7f6e\u6587\u4ef6<\/h4>\n<p><span class=\"token comment\"># \u521b\u5efa\u6216\u7f16\u8f91SSH\u914d\u7f6e\u6587\u4ef6<\/span><br \/>\n<span class=\"token function\">nano<\/span> ~\/.ssh\/config<\/p>\n<p><span class=\"token comment\"># \u914d\u7f6e\u793a\u4f8b<\/span><br \/>\nHost myserver<br \/>\n    HostName <span class=\"token number\">192.168<\/span>.1.100<br \/>\n    User ubuntu<br \/>\n    Port <span class=\"token number\">22<\/span><br \/>\n    IdentityFile ~\/.ssh\/id_rsa<\/p>\n<p>Host production<br \/>\n    HostName prod.example.com<br \/>\n    User deploy<br \/>\n    Port <span class=\"token number\">2222<\/span><br \/>\n    IdentityFile ~\/.ssh\/prod_key<\/p>\n<p>Host development<br \/>\n    HostName dev.example.com<br \/>\n    User developer<br \/>\n    Port <span class=\"token number\">22<\/span><br \/>\n    IdentityFile ~\/.ssh\/dev_key<\/p>\n<p><span class=\"token comment\"># \u901a\u914d\u7b26\u914d\u7f6e<\/span><br \/>\nHost *.example.com<br \/>\n    User admin<br \/>\n    Port <span class=\"token number\">2222<\/span><br \/>\n    ServerAliveInterval <span class=\"token number\">60<\/span><br \/>\n    ServerAliveCountMax <span class=\"token number\">3<\/span><\/p>\n<p>\u914d\u7f6e\u6587\u4ef6\u7684\u4f18\u52bf&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u539f\u6765\u9700\u8981\u8fd9\u6837\u8fde\u63a5<\/span><br \/>\n<span class=\"token function\">ssh<\/span> -i ~\/.ssh\/prod_key -p <span class=\"token number\">2222<\/span> deploy&#064;prod.example.com<\/p>\n<p><span class=\"token comment\"># \u73b0\u5728\u53ea\u9700\u8981<\/span><br \/>\n<span class=\"token function\">ssh<\/span> production<\/p>\n<h4>\u5e38\u7528\u914d\u7f6e\u9009\u9879\u8be6\u89e3<\/h4>\n<p><span class=\"token comment\"># \u57fa\u672c\u8fde\u63a5\u914d\u7f6e<\/span><br \/>\nHost myserver<br \/>\n    HostName server.example.com      <span class=\"token comment\"># \u670d\u52a1\u5668\u5730\u5740<\/span><br \/>\n    User username                    <span class=\"token comment\"># \u7528\u6237\u540d<\/span><br \/>\n    Port <span class=\"token number\">22<\/span>                         <span class=\"token comment\"># SSH\u7aef\u53e3<\/span><br \/>\n    IdentityFile ~\/.ssh\/id_rsa      <span class=\"token comment\"># \u79c1\u94a5\u6587\u4ef6\u8def\u5f84<\/span><\/p>\n<p><span class=\"token comment\"># \u8fde\u63a5\u4f18\u5316\u914d\u7f6e<\/span><br \/>\n    ServerAliveInterval <span class=\"token number\">60<\/span>          <span class=\"token comment\"># \u6bcf60\u79d2\u53d1\u9001\u5fc3\u8df3\u5305<\/span><br \/>\n    ServerAliveCountMax <span class=\"token number\">3<\/span>           <span class=\"token comment\"># \u6700\u591a3\u6b21\u5fc3\u8df3\u5931\u8d25\u540e\u65ad\u5f00<\/span><br \/>\n    ConnectTimeout <span class=\"token number\">10<\/span>               <span class=\"token comment\"># \u8fde\u63a5\u8d85\u65f6\u65f6\u95f4<\/span><\/p>\n<p><span class=\"token comment\"># \u8fde\u63a5\u590d\u7528\u914d\u7f6e<\/span><br \/>\n    ControlMaster auto              <span class=\"token comment\"># \u81ea\u52a8\u590d\u7528\u8fde\u63a5<\/span><br \/>\n    ControlPath ~\/.ssh\/master-%r&#064;%h:%p  <span class=\"token comment\"># \u63a7\u5236\u6587\u4ef6\u8def\u5f84<\/span><br \/>\n    ControlPersist 10m              <span class=\"token comment\"># \u4fdd\u6301\u8fde\u63a510\u5206\u949f<\/span><\/p>\n<p><span class=\"token comment\"># \u5b89\u5168\u914d\u7f6e<\/span><br \/>\n    StrictHostKeyChecking <span class=\"token function\">yes<\/span>       <span class=\"token comment\"># \u4e25\u683c\u68c0\u67e5\u4e3b\u673a\u5bc6\u94a5<\/span><br \/>\n    UserKnownHostsFile ~\/.ssh\/known_hosts  <span class=\"token comment\"># \u5df2\u77e5\u4e3b\u673a\u6587\u4ef6<\/span><\/p>\n<h3>\u7b2c\u4e94\u6b65&#xff1a;\u6587\u4ef6\u4f20\u8f93 &#8211; SSH\u7684\u5f3a\u5927\u529f\u80fd<\/h3>\n<h4>SCP &#8211; \u7b80\u5355\u6587\u4ef6\u590d\u5236<\/h4>\n<p><span class=\"token comment\"># \u4e0a\u4f20\u6587\u4ef6\u5230\u670d\u52a1\u5668<\/span><br \/>\n<span class=\"token function\">scp<\/span> local_file.txt username&#064;server:\/path\/to\/destination\/<\/p>\n<p><span class=\"token comment\"># \u4e0b\u8f7d\u6587\u4ef6\u4ece\u670d\u52a1\u5668<\/span><br \/>\n<span class=\"token function\">scp<\/span> username&#064;server:\/path\/to\/file.txt .\/local_directory\/<\/p>\n<p><span class=\"token comment\"># \u9012\u5f52\u590d\u5236\u76ee\u5f55<\/span><br \/>\n<span class=\"token function\">scp<\/span> -r local_directory\/ username&#064;server:\/path\/to\/destination\/<\/p>\n<p><span class=\"token comment\"># \u4fdd\u6301\u6587\u4ef6\u6743\u9650\u548c\u65f6\u95f4\u6233<\/span><br \/>\n<span class=\"token function\">scp<\/span> -p file.txt username&#064;server:\/path\/to\/destination\/<\/p>\n<p><span class=\"token comment\"># \u538b\u7f29\u4f20\u8f93&#xff08;\u8282\u7701\u5e26\u5bbd&#xff09;<\/span><br \/>\n<span class=\"token function\">scp<\/span> -C large_file.zip username&#064;server:\/path\/to\/destination\/<\/p>\n<h4>SFTP &#8211; \u4ea4\u4e92\u5f0f\u6587\u4ef6\u7ba1\u7406<\/h4>\n<p><span class=\"token comment\"># \u542f\u52a8SFTP\u4f1a\u8bdd<\/span><br \/>\n<span class=\"token function\">sftp<\/span> username&#064;server<\/p>\n<p><span class=\"token comment\"># SFTP\u5e38\u7528\u547d\u4ee4<\/span><br \/>\nsftp<span class=\"token operator\">&gt;<\/span> <span class=\"token builtin class-name\">pwd<\/span>                    <span class=\"token comment\"># \u663e\u793a\u8fdc\u7a0b\u5f53\u524d\u76ee\u5f55<\/span><br \/>\nsftp<span class=\"token operator\">&gt;<\/span> lpwd                   <span class=\"token comment\"># \u663e\u793a\u672c\u5730\u5f53\u524d\u76ee\u5f55<\/span><br \/>\nsftp<span class=\"token operator\">&gt;<\/span> <span class=\"token function\">ls<\/span>                     <span class=\"token comment\"># \u5217\u51fa\u8fdc\u7a0b\u76ee\u5f55\u5185\u5bb9<\/span><br \/>\nsftp<span class=\"token operator\">&gt;<\/span> lls                    <span class=\"token comment\"># \u5217\u51fa\u672c\u5730\u76ee\u5f55\u5185\u5bb9<\/span><br \/>\nsftp<span class=\"token operator\">&gt;<\/span> <span class=\"token builtin class-name\">cd<\/span> \/path\/to\/directory  <span class=\"token comment\"># \u5207\u6362\u8fdc\u7a0b\u76ee\u5f55<\/span><br \/>\nsftp<span class=\"token operator\">&gt;<\/span> lcd \/local\/path        <span class=\"token comment\"># \u5207\u6362\u672c\u5730\u76ee\u5f55<\/span><br \/>\nsftp<span class=\"token operator\">&gt;<\/span> get remote_file.txt    <span class=\"token comment\"># \u4e0b\u8f7d\u6587\u4ef6<\/span><br \/>\nsftp<span class=\"token operator\">&gt;<\/span> put local_file.txt     <span class=\"token comment\"># \u4e0a\u4f20\u6587\u4ef6<\/span><br \/>\nsftp<span class=\"token operator\">&gt;<\/span> <span class=\"token function\">mkdir<\/span> new_directory    <span class=\"token comment\"># \u521b\u5efa\u8fdc\u7a0b\u76ee\u5f55<\/span><br \/>\nsftp<span class=\"token operator\">&gt;<\/span> <span class=\"token function\">rmdir<\/span> directory_name   <span class=\"token comment\"># \u5220\u9664\u8fdc\u7a0b\u76ee\u5f55<\/span><br \/>\nsftp<span class=\"token operator\">&gt;<\/span> <span class=\"token function\">rm<\/span> file.txt           <span class=\"token comment\"># \u5220\u9664\u8fdc\u7a0b\u6587\u4ef6<\/span><br \/>\nsftp<span class=\"token operator\">&gt;<\/span> <span class=\"token builtin class-name\">exit<\/span>                  <span class=\"token comment\"># \u9000\u51faSFTP<\/span><\/p>\n<h4>RSYNC &#8211; \u589e\u91cf\u540c\u6b65\u4f20\u8f93<\/h4>\n<p><span class=\"token comment\"># \u57fa\u672c\u540c\u6b65\u547d\u4ee4<\/span><br \/>\n<span class=\"token function\">rsync<\/span> -avz local_directory\/ username&#064;server:\/path\/to\/destination\/<\/p>\n<p><span class=\"token comment\"># \u53c2\u6570\u8bf4\u660e&#xff1a;<\/span><br \/>\n<span class=\"token comment\"># -a: \u5f52\u6863\u6a21\u5f0f&#xff08;\u4fdd\u6301\u6743\u9650\u3001\u65f6\u95f4\u6233\u7b49&#xff09;<\/span><br \/>\n<span class=\"token comment\"># -v: \u8be6\u7ec6\u8f93\u51fa<\/span><br \/>\n<span class=\"token comment\"># -z: \u538b\u7f29\u4f20\u8f93<\/span><\/p>\n<p><span class=\"token comment\"># \u6392\u9664\u7279\u5b9a\u6587\u4ef6<\/span><br \/>\n<span class=\"token function\">rsync<\/span> -avz &#8211;exclude<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;*.log&#039;<\/span> &#8211;exclude<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;node_modules\/&#039;<\/span> project\/ server:\/var\/www\/<\/p>\n<p><span class=\"token comment\"># \u5220\u9664\u76ee\u6807\u76ee\u5f55\u4e2d\u591a\u4f59\u7684\u6587\u4ef6<\/span><br \/>\n<span class=\"token function\">rsync<\/span> -avz &#8211;delete local_directory\/ server:\/path\/to\/destination\/<\/p>\n<p><span class=\"token comment\"># \u663e\u793a\u4f20\u8f93\u8fdb\u5ea6<\/span><br \/>\n<span class=\"token function\">rsync<\/span> -avz &#8211;progress large_file.zip server:\/path\/to\/destination\/<\/p>\n<p><span class=\"token comment\"># \u9650\u5236\u4f20\u8f93\u901f\u5ea6&#xff08;KB\/s&#xff09;<\/span><br \/>\n<span class=\"token function\">rsync<\/span> -avz &#8211;bwlimit<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1000<\/span> large_directory\/ server:\/path\/to\/destination\/<\/p>\n<h3>\u7b2c\u516d\u6b65&#xff1a;\u7aef\u53e3\u8f6c\u53d1 &#8211; SSH\u7684\u9ad8\u7ea7\u529f\u80fd<\/h3>\n<h4>\u672c\u5730\u7aef\u53e3\u8f6c\u53d1<\/h4>\n<p><span class=\"token comment\"># \u5c06\u672c\u5730\u7aef\u53e3\u8f6c\u53d1\u5230\u8fdc\u7a0b\u670d\u52a1\u5668<\/span><br \/>\n<span class=\"token function\">ssh<\/span> -L local_port:destination_host:destination_port username&#064;server<\/p>\n<p><span class=\"token comment\"># \u5b9e\u9645\u4f8b\u5b50&#xff1a;\u8bbf\u95ee\u8fdc\u7a0b\u6570\u636e\u5e93<\/span><br \/>\n<span class=\"token function\">ssh<\/span> -L <span class=\"token number\">3306<\/span>:localhost:3306 username&#064;db_server<br \/>\n<span class=\"token comment\"># \u73b0\u5728\u53ef\u4ee5\u901a\u8fc7 localhost:3306 \u8bbf\u95ee\u8fdc\u7a0b\u6570\u636e\u5e93<\/span><\/p>\n<p><span class=\"token comment\"># \u540e\u53f0\u8fd0\u884c\u7aef\u53e3\u8f6c\u53d1<\/span><br \/>\n<span class=\"token function\">ssh<\/span> -f -N -L <span class=\"token number\">8080<\/span>:localhost:80 username&#064;web_server<\/p>\n<h4>\u8fdc\u7a0b\u7aef\u53e3\u8f6c\u53d1<\/h4>\n<p><span class=\"token comment\"># \u5c06\u8fdc\u7a0b\u7aef\u53e3\u8f6c\u53d1\u5230\u672c\u5730<\/span><br \/>\n<span class=\"token function\">ssh<\/span> -R remote_port:localhost:local_port username&#064;server<\/p>\n<p><span class=\"token comment\"># \u5b9e\u9645\u4f8b\u5b50&#xff1a;\u8ba9\u8fdc\u7a0b\u670d\u52a1\u5668\u8bbf\u95ee\u672c\u5730\u670d\u52a1<\/span><br \/>\n<span class=\"token function\">ssh<\/span> -R <span class=\"token number\">8080<\/span>:localhost:3000 username&#064;server<br \/>\n<span class=\"token comment\"># \u8fdc\u7a0b\u670d\u52a1\u5668\u53ef\u4ee5\u901a\u8fc7 localhost:8080 \u8bbf\u95ee\u672c\u5730\u76843000\u7aef\u53e3<\/span><\/p>\n<h4>\u52a8\u6001\u7aef\u53e3\u8f6c\u53d1&#xff08;SOCKS\u4ee3\u7406&#xff09;<\/h4>\n<p><span class=\"token comment\"># \u521b\u5efaSOCKS\u4ee3\u7406<\/span><br \/>\n<span class=\"token function\">ssh<\/span> -D <span class=\"token number\">1080<\/span> username&#064;server<\/p>\n<p><span class=\"token comment\"># \u914d\u7f6e\u6d4f\u89c8\u5668\u4f7f\u7528SOCKS\u4ee3\u7406 127.0.0.1:1080<\/span><br \/>\n<span class=\"token comment\"># \u6240\u6709\u6d41\u91cf\u90fd\u4f1a\u901a\u8fc7SSH\u670d\u52a1\u5668\u8f6c\u53d1<\/span><\/p>\n<h3>\u7b2c\u4e03\u6b65&#xff1a;Python\u9879\u76ee\u4e2d\u7684SSH\u5e94\u7528<\/h3>\n<h4>\u4f7f\u7528paramiko\u5e93\u8fdb\u884cSSH\u64cd\u4f5c<\/h4>\n<p><span class=\"token keyword\">import<\/span> paramiko<br \/>\n<span class=\"token keyword\">import<\/span> os<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">SSHManager<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> hostname<span class=\"token punctuation\">,<\/span> username<span class=\"token punctuation\">,<\/span> key_filename<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">None<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>hostname <span class=\"token operator\">&#061;<\/span> hostname<br \/>\n        self<span class=\"token punctuation\">.<\/span>username <span class=\"token operator\">&#061;<\/span> username<br \/>\n        self<span class=\"token punctuation\">.<\/span>key_filename <span class=\"token operator\">&#061;<\/span> key_filename<br \/>\n        self<span class=\"token punctuation\">.<\/span>client <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">None<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">connect<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u5efa\u7acbSSH\u8fde\u63a5&#034;&#034;&#034;<\/span><br \/>\n        <span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            self<span class=\"token punctuation\">.<\/span>client <span class=\"token operator\">&#061;<\/span> paramiko<span class=\"token punctuation\">.<\/span>SSHClient<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            self<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>set_missing_host_key_policy<span class=\"token punctuation\">(<\/span>paramiko<span class=\"token punctuation\">.<\/span>AutoAddPolicy<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>            <span class=\"token keyword\">if<\/span> self<span class=\"token punctuation\">.<\/span>key_filename<span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token comment\"># \u4f7f\u7528\u5bc6\u94a5\u8ba4\u8bc1<\/span><br \/>\n                self<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>connect<span class=\"token punctuation\">(<\/span><br \/>\n                    hostname<span class=\"token operator\">&#061;<\/span>self<span class=\"token punctuation\">.<\/span>hostname<span class=\"token punctuation\">,<\/span><br \/>\n                    username<span class=\"token operator\">&#061;<\/span>self<span class=\"token punctuation\">.<\/span>username<span class=\"token punctuation\">,<\/span><br \/>\n                    key_filename<span class=\"token operator\">&#061;<\/span>self<span class=\"token punctuation\">.<\/span>key_filename<br \/>\n                <span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">else<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token comment\"># \u4f7f\u7528\u5bc6\u7801\u8ba4\u8bc1<\/span><br \/>\n                password <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">input<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Enter password for <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>self<span class=\"token punctuation\">.<\/span>username<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#064;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>self<span class=\"token punctuation\">.<\/span>hostname<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">: &#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n                self<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>connect<span class=\"token punctuation\">(<\/span><br \/>\n                    hostname<span class=\"token operator\">&#061;<\/span>self<span class=\"token punctuation\">.<\/span>hostname<span class=\"token punctuation\">,<\/span><br \/>\n                    username<span class=\"token operator\">&#061;<\/span>self<span class=\"token punctuation\">.<\/span>username<span class=\"token punctuation\">,<\/span><br \/>\n                    password<span class=\"token operator\">&#061;<\/span>password<br \/>\n                <span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Connected to <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>self<span class=\"token punctuation\">.<\/span>hostname<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">True<\/span><br \/>\n        <span class=\"token keyword\">except<\/span> Exception <span class=\"token keyword\">as<\/span> e<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Connection failed: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>e<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">False<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">execute_command<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> command<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u6267\u884c\u8fdc\u7a0b\u547d\u4ee4&#034;&#034;&#034;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token keyword\">not<\/span> self<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Not connected to server&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">None<\/span><\/p>\n<p>        <span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            stdin<span class=\"token punctuation\">,<\/span> stdout<span class=\"token punctuation\">,<\/span> stderr <span class=\"token operator\">&#061;<\/span> self<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>exec_command<span class=\"token punctuation\">(<\/span>command<span class=\"token punctuation\">)<\/span><br \/>\n            output <span class=\"token operator\">&#061;<\/span> stdout<span class=\"token punctuation\">.<\/span>read<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>decode<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            error <span class=\"token operator\">&#061;<\/span> stderr<span class=\"token punctuation\">.<\/span>read<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>decode<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>            <span class=\"token keyword\">if<\/span> error<span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Error: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>error<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>            <span class=\"token keyword\">return<\/span> output<br \/>\n        <span class=\"token keyword\">except<\/span> Exception <span class=\"token keyword\">as<\/span> e<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Command execution failed: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>e<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">None<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">upload_file<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> local_path<span class=\"token punctuation\">,<\/span> remote_path<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u4e0a\u4f20\u6587\u4ef6&#034;&#034;&#034;<\/span><br \/>\n        <span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            sftp <span class=\"token operator\">&#061;<\/span> self<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>open_sftp<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            sftp<span class=\"token punctuation\">.<\/span>put<span class=\"token punctuation\">(<\/span>local_path<span class=\"token punctuation\">,<\/span> remote_path<span class=\"token punctuation\">)<\/span><br \/>\n            sftp<span class=\"token punctuation\">.<\/span>close<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Uploaded <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>local_path<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> to <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>remote_path<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">True<\/span><br \/>\n        <span class=\"token keyword\">except<\/span> Exception <span class=\"token keyword\">as<\/span> e<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Upload failed: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>e<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">False<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">download_file<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> remote_path<span class=\"token punctuation\">,<\/span> local_path<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u4e0b\u8f7d\u6587\u4ef6&#034;&#034;&#034;<\/span><br \/>\n        <span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            sftp <span class=\"token operator\">&#061;<\/span> self<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>open_sftp<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            sftp<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span>remote_path<span class=\"token punctuation\">,<\/span> local_path<span class=\"token punctuation\">)<\/span><br \/>\n            sftp<span class=\"token punctuation\">.<\/span>close<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Downloaded <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>remote_path<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> to <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>local_path<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">True<\/span><br \/>\n        <span class=\"token keyword\">except<\/span> Exception <span class=\"token keyword\">as<\/span> e<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Download failed: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>e<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">False<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u5173\u95ed\u8fde\u63a5&#034;&#034;&#034;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> self<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">:<\/span><br \/>\n            self<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>close<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Connection closed&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u4f7f\u7528\u793a\u4f8b<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">deploy_python_app<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u8fde\u63a5\u5230\u670d\u52a1\u5668<\/span><br \/>\n    ssh <span class=\"token operator\">&#061;<\/span> SSHManager<span class=\"token punctuation\">(<\/span><br \/>\n        hostname<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;your-server.com&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        username<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;ubuntu&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        key_filename<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;~\/.ssh\/id_rsa&#039;<\/span><br \/>\n    <span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">if<\/span> ssh<span class=\"token punctuation\">.<\/span>connect<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token comment\"># \u66f4\u65b0\u4ee3\u7801<\/span><br \/>\n        ssh<span class=\"token punctuation\">.<\/span>execute_command<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;cd \/opt\/myapp &amp;&amp; git pull origin main&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\"># \u5b89\u88c5\u4f9d\u8d56<\/span><br \/>\n        ssh<span class=\"token punctuation\">.<\/span>execute_command<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;cd \/opt\/myapp &amp;&amp; pip install -r requirements.txt&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\"># \u91cd\u542f\u670d\u52a1<\/span><br \/>\n        ssh<span class=\"token punctuation\">.<\/span>execute_command<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;sudo systemctl restart myapp&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\"># \u68c0\u67e5\u670d\u52a1\u72b6\u6001<\/span><br \/>\n        status <span class=\"token operator\">&#061;<\/span> ssh<span class=\"token punctuation\">.<\/span>execute_command<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;sudo systemctl status myapp&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Service status:\\\\n<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>status<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        ssh<span class=\"token punctuation\">.<\/span>close<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">if<\/span> __name__ <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#034;__main__&#034;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    deploy_python_app<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<h4>\u81ea\u52a8\u5316\u90e8\u7f72\u811a\u672c<\/h4>\n<p><span class=\"token shebang important\">#!\/bin\/bash<\/span><br \/>\n<span class=\"token comment\"># deploy.sh &#8211; \u81ea\u52a8\u5316\u90e8\u7f72\u811a\u672c<\/span><\/p>\n<p><span class=\"token comment\"># \u914d\u7f6e\u53d8\u91cf<\/span><br \/>\n<span class=\"token assign-left variable\">SERVER<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;production&#034;<\/span>  <span class=\"token comment\"># SSH\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u4e3b\u673a\u540d<\/span><br \/>\n<span class=\"token assign-left variable\">APP_DIR<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\/opt\/myapp&#034;<\/span><br \/>\n<span class=\"token assign-left variable\">BACKUP_DIR<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\/opt\/backups&#034;<\/span><\/p>\n<p><span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;Starting deployment&#8230;&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 1. \u521b\u5efa\u5907\u4efd<\/span><br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;Creating backup&#8230;&#034;<\/span><br \/>\n<span class=\"token function\">ssh<\/span> <span class=\"token variable\">$SERVER<\/span> <span class=\"token string\">&#034;sudo tar -czf <span class=\"token variable\">$BACKUP_DIR<\/span>\/backup_<span class=\"token variable\"><span class=\"token variable\">$(<\/span><span class=\"token function\">date<\/span> &#043;%Y%m%d_%H%M%S<span class=\"token variable\">)<\/span><\/span>.tar.gz <span class=\"token variable\">$APP_DIR<\/span>&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 2. \u4e0a\u4f20\u65b0\u4ee3\u7801<\/span><br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;Uploading code&#8230;&#034;<\/span><br \/>\n<span class=\"token function\">rsync<\/span> -avz &#8211;delete <span class=\"token punctuation\">\\\\<\/span><br \/>\n    &#8211;exclude<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;.git&#039;<\/span> <span class=\"token punctuation\">\\\\<\/span><br \/>\n    &#8211;exclude<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;__pycache__&#039;<\/span> <span class=\"token punctuation\">\\\\<\/span><br \/>\n    &#8211;exclude<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;*.pyc&#039;<\/span> <span class=\"token punctuation\">\\\\<\/span><br \/>\n    &#8211;exclude<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;venv\/&#039;<\/span> <span class=\"token punctuation\">\\\\<\/span><br \/>\n    .\/ <span class=\"token variable\">$SERVER<\/span><span class=\"token builtin class-name\">:<\/span><span class=\"token variable\">$APP_DIR<\/span>\/<\/p>\n<p><span class=\"token comment\"># 3. \u5b89\u88c5\u4f9d\u8d56<\/span><br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;Installing dependencies&#8230;&#034;<\/span><br \/>\n<span class=\"token function\">ssh<\/span> <span class=\"token variable\">$SERVER<\/span> <span class=\"token string\">&#034;cd <span class=\"token variable\">$APP_DIR<\/span> &amp;&amp; source venv\/bin\/activate &amp;&amp; pip install -r requirements.txt&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 4. \u8fd0\u884c\u6570\u636e\u5e93\u8fc1\u79fb<\/span><br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;Running database migrations&#8230;&#034;<\/span><br \/>\n<span class=\"token function\">ssh<\/span> <span class=\"token variable\">$SERVER<\/span> <span class=\"token string\">&#034;cd <span class=\"token variable\">$APP_DIR<\/span> &amp;&amp; source venv\/bin\/activate &amp;&amp; python manage.py migrate&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 5. \u91cd\u542f\u670d\u52a1<\/span><br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;Restarting service&#8230;&#034;<\/span><br \/>\n<span class=\"token function\">ssh<\/span> <span class=\"token variable\">$SERVER<\/span> <span class=\"token string\">&#034;sudo systemctl restart myapp&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 6. \u68c0\u67e5\u670d\u52a1\u72b6\u6001<\/span><br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;Checking service status&#8230;&#034;<\/span><br \/>\n<span class=\"token function\">ssh<\/span> <span class=\"token variable\">$SERVER<\/span> <span class=\"token string\">&#034;sudo systemctl status myapp &#8211;no-pager&#034;<\/span><\/p>\n<p><span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;Deployment completed!&#034;<\/span><\/p>\n<h3>\u7b2c\u516b\u6b65&#xff1a;SSH\u5b89\u5168\u6700\u4f73\u5b9e\u8df5<\/h3>\n<h4>\u670d\u52a1\u5668\u7aef\u5b89\u5168\u914d\u7f6e<\/h4>\n<p><span class=\"token comment\"># \u7f16\u8f91SSH\u670d\u52a1\u914d\u7f6e<\/span><br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">nano<\/span> \/etc\/ssh\/sshd_config<\/p>\n<p><span class=\"token comment\"># \u63a8\u8350\u7684\u5b89\u5168\u914d\u7f6e<\/span><br \/>\nPort <span class=\"token number\">2222<\/span>                          <span class=\"token comment\"># \u66f4\u6539\u9ed8\u8ba4\u7aef\u53e3<\/span><br \/>\nPermitRootLogin no                 <span class=\"token comment\"># \u7981\u6b62root\u76f4\u63a5\u767b\u5f55<\/span><br \/>\nPasswordAuthentication no          <span class=\"token comment\"># \u7981\u7528\u5bc6\u7801\u8ba4\u8bc1<\/span><br \/>\nPubkeyAuthentication <span class=\"token function\">yes<\/span>           <span class=\"token comment\"># \u542f\u7528\u516c\u94a5\u8ba4\u8bc1<\/span><br \/>\nAuthorizedKeysFile .ssh\/authorized_keys<br \/>\nMaxAuthTries <span class=\"token number\">3<\/span>                     <span class=\"token comment\"># \u6700\u591a\u5c1d\u8bd53\u6b21\u8ba4\u8bc1<\/span><br \/>\nClientAliveInterval <span class=\"token number\">300<\/span>            <span class=\"token comment\"># 5\u5206\u949f\u65e0\u6d3b\u52a8\u65ad\u5f00\u8fde\u63a5<\/span><br \/>\nClientAliveCountMax <span class=\"token number\">2<\/span>              <span class=\"token comment\"># \u6700\u591a2\u6b21\u5fc3\u8df3\u5931\u8d25<\/span><br \/>\nX11Forwarding no                   <span class=\"token comment\"># \u7981\u7528X11\u8f6c\u53d1<\/span><br \/>\nAllowTcpForwarding no             <span class=\"token comment\"># \u7981\u7528TCP\u8f6c\u53d1&#xff08;\u5982\u679c\u4e0d\u9700\u8981&#xff09;<\/span><\/p>\n<p><span class=\"token comment\"># \u9650\u5236\u7528\u6237\u548c\u7ec4<\/span><br \/>\nAllowUsers ubuntu deploy           <span class=\"token comment\"># \u53ea\u5141\u8bb8\u7279\u5b9a\u7528\u6237<\/span><br \/>\nAllowGroups ssh-users             <span class=\"token comment\"># \u53ea\u5141\u8bb8\u7279\u5b9a\u7ec4<\/span><\/p>\n<p><span class=\"token comment\"># \u91cd\u542fSSH\u670d\u52a1<\/span><br \/>\n<span class=\"token function\">sudo<\/span> systemctl restart sshd<\/p>\n<h4>\u5ba2\u6237\u7aef\u5b89\u5168\u914d\u7f6e<\/h4>\n<p><span class=\"token comment\"># ~\/.ssh\/config \u5b89\u5168\u914d\u7f6e<\/span><br \/>\nHost *<br \/>\n    <span class=\"token comment\"># \u5b89\u5168\u9009\u9879<\/span><br \/>\n    StrictHostKeyChecking <span class=\"token function\">yes<\/span><br \/>\n    UserKnownHostsFile ~\/.ssh\/known_hosts<br \/>\n    VisualHostKey <span class=\"token function\">yes<\/span><\/p>\n<p>    <span class=\"token comment\"># \u52a0\u5bc6\u7b97\u6cd5\u9009\u62e9<\/span><br \/>\n    KexAlgorithms curve25519-sha256&#064;libssh.org,diffie-hellman-group16-sha512<br \/>\n    HostKeyAlgorithms rsa-sha2-512,rsa-sha2-256,ssh-ed25519<br \/>\n    Ciphers chacha20-poly1305&#064;openssh.com,aes256-gcm&#064;openssh.com,aes128-gcm&#064;openssh.com,aes256-ctr,aes192-ctr,aes128-ctr<br \/>\n    MACs hmac-sha2-256-etm&#064;openssh.com,hmac-sha2-512-etm&#064;openssh.com,hmac-sha2-256,hmac-sha2-512<\/p>\n<p>    <span class=\"token comment\"># \u8fde\u63a5\u4f18\u5316<\/span><br \/>\n    ServerAliveInterval <span class=\"token number\">60<\/span><br \/>\n    ServerAliveCountMax <span class=\"token number\">3<\/span><br \/>\n    ConnectTimeout <span class=\"token number\">10<\/span><\/p>\n<h4>\u5bc6\u94a5\u7ba1\u7406\u6700\u4f73\u5b9e\u8df5<\/h4>\n<p><span class=\"token comment\"># 1. \u4e3a\u4e0d\u540c\u7528\u9014\u521b\u5efa\u4e0d\u540c\u7684\u5bc6\u94a5<\/span><br \/>\nssh-keygen -t ed25519 -f ~\/.ssh\/id_ed25519_work -C <span class=\"token string\">&#034;work_email&#064;company.com&#034;<\/span><br \/>\nssh-keygen -t ed25519 -f ~\/.ssh\/id_ed25519_personal -C <span class=\"token string\">&#034;personal_email&#064;example.com&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 2. \u8bbe\u7f6e\u6b63\u786e\u7684\u6743\u9650<\/span><br \/>\n<span class=\"token function\">chmod<\/span> <span class=\"token number\">700<\/span> ~\/.ssh<br \/>\n<span class=\"token function\">chmod<\/span> <span class=\"token number\">600<\/span> ~\/.ssh\/id_*<br \/>\n<span class=\"token function\">chmod<\/span> <span class=\"token number\">644<\/span> ~\/.ssh\/id_*.pub<br \/>\n<span class=\"token function\">chmod<\/span> <span class=\"token number\">644<\/span> ~\/.ssh\/config<\/p>\n<p><span class=\"token comment\"># 3. \u5b9a\u671f\u8f6e\u6362\u5bc6\u94a5<\/span><br \/>\n<span class=\"token comment\"># \u521b\u5efa\u65b0\u5bc6\u94a5 -&gt; \u90e8\u7f72\u5230\u670d\u52a1\u5668 -&gt; \u6d4b\u8bd5\u8fde\u63a5 -&gt; \u5220\u9664\u65e7\u5bc6\u94a5<\/span><\/p>\n<p><span class=\"token comment\"># 4. \u4f7f\u7528SSH Agent\u7ba1\u7406\u5bc6\u94a5<\/span><br \/>\n<span class=\"token builtin class-name\">eval<\/span> <span class=\"token string\">&#034;<span class=\"token variable\"><span class=\"token variable\">$(<\/span>ssh-agent -s<span class=\"token variable\">)<\/span><\/span>&#034;<\/span><br \/>\nssh-add ~\/.ssh\/id_ed25519<br \/>\nssh-add -l  <span class=\"token comment\"># \u67e5\u770b\u5df2\u52a0\u8f7d\u7684\u5bc6\u94a5<\/span><\/p>\n<h3>\u7b2c\u4e5d\u6b65&#xff1a;\u6545\u969c\u6392\u9664\u4e0e\u8c03\u8bd5<\/h3>\n<h4>\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848<\/h4>\n<h5>\u95ee\u98981&#xff1a;\u8fde\u63a5\u88ab\u62d2\u7edd<\/h5>\n<p><span class=\"token comment\"># \u9519\u8bef\u4fe1\u606f<\/span><br \/>\nssh: connect to <span class=\"token function\">host<\/span> server.com port <span class=\"token number\">22<\/span>: Connection refused<\/p>\n<p><span class=\"token comment\"># \u89e3\u51b3\u65b9\u6848<\/span><br \/>\n<span class=\"token comment\"># 1. \u68c0\u67e5\u670d\u52a1\u5668SSH\u670d\u52a1\u72b6\u6001<\/span><br \/>\n<span class=\"token function\">sudo<\/span> systemctl status sshd<\/p>\n<p><span class=\"token comment\"># 2. \u68c0\u67e5\u9632\u706b\u5899\u8bbe\u7f6e<\/span><br \/>\n<span class=\"token function\">sudo<\/span> ufw status<br \/>\n<span class=\"token function\">sudo<\/span> ufw allow <span class=\"token number\">22<\/span><\/p>\n<p><span class=\"token comment\"># 3. \u68c0\u67e5\u7aef\u53e3\u662f\u5426\u6b63\u786e<\/span><br \/>\nnmap -p <span class=\"token number\">22<\/span> server.com<\/p>\n<h5>\u95ee\u98982&#xff1a;\u5bc6\u94a5\u8ba4\u8bc1\u5931\u8d25<\/h5>\n<p><span class=\"token comment\"># \u9519\u8bef\u4fe1\u606f<\/span><br \/>\nPermission denied <span class=\"token punctuation\">(<\/span>publickey<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u89e3\u51b3\u65b9\u6848<\/span><br \/>\n<span class=\"token comment\"># 1. \u68c0\u67e5\u5bc6\u94a5\u6743\u9650<\/span><br \/>\n<span class=\"token function\">ls<\/span> -la ~\/.ssh\/<br \/>\n<span class=\"token function\">chmod<\/span> <span class=\"token number\">600<\/span> ~\/.ssh\/id_rsa<br \/>\n<span class=\"token function\">chmod<\/span> <span class=\"token number\">644<\/span> ~\/.ssh\/id_rsa.pub<\/p>\n<p><span class=\"token comment\"># 2. \u68c0\u67e5\u670d\u52a1\u5668authorized_keys<\/span><br \/>\n<span class=\"token function\">ssh<\/span> username&#064;server <span class=\"token string\">&#034;ls -la ~\/.ssh\/&#034;<\/span><br \/>\n<span class=\"token function\">ssh<\/span> username&#064;server <span class=\"token string\">&#034;cat ~\/.ssh\/authorized_keys&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 3. \u68c0\u67e5SSH\u914d\u7f6e<\/span><br \/>\n<span class=\"token function\">ssh<\/span> -vvv username&#064;server  <span class=\"token comment\"># \u8be6\u7ec6\u8c03\u8bd5\u4fe1\u606f<\/span><\/p>\n<h5>\u95ee\u98983&#xff1a;\u8fde\u63a5\u8d85\u65f6<\/h5>\n<p><span class=\"token comment\"># \u9519\u8bef\u4fe1\u606f<\/span><br \/>\nssh: connect to <span class=\"token function\">host<\/span> server.com port <span class=\"token number\">22<\/span>: Connection timed out<\/p>\n<p><span class=\"token comment\"># \u89e3\u51b3\u65b9\u6848<\/span><br \/>\n<span class=\"token comment\"># 1. \u68c0\u67e5\u7f51\u7edc\u8fde\u63a5<\/span><br \/>\n<span class=\"token function\">ping<\/span> server.com<br \/>\ntelnet server.com <span class=\"token number\">22<\/span><\/p>\n<p><span class=\"token comment\"># 2. \u68c0\u67e5\u670d\u52a1\u5668\u9632\u706b\u5899<\/span><br \/>\n<span class=\"token function\">sudo<\/span> iptables -L<br \/>\n<span class=\"token function\">sudo<\/span> ufw status verbose<\/p>\n<p><span class=\"token comment\"># 3. \u68c0\u67e5\u4e91\u670d\u52a1\u5546\u5b89\u5168\u7ec4\u8bbe\u7f6e<\/span><\/p>\n<h4>SSH\u8c03\u8bd5\u6280\u5de7<\/h4>\n<p><span class=\"token comment\"># \u8be6\u7ec6\u8c03\u8bd5\u4fe1\u606f<\/span><br \/>\n<span class=\"token function\">ssh<\/span> -vvv username&#064;server<\/p>\n<p><span class=\"token comment\"># \u6307\u5b9a\u914d\u7f6e\u6587\u4ef6<\/span><br \/>\n<span class=\"token function\">ssh<\/span> -F \/path\/to\/config username&#064;server<\/p>\n<p><span class=\"token comment\"># \u6d4b\u8bd5\u914d\u7f6e\u6587\u4ef6<\/span><br \/>\n<span class=\"token function\">ssh<\/span> -T username&#064;server<\/p>\n<p><span class=\"token comment\"># \u68c0\u67e5SSH\u670d\u52a1\u65e5\u5fd7<\/span><br \/>\n<span class=\"token function\">sudo<\/span> journalctl -u sshd -f<br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">tail<\/span> -f \/var\/log\/auth.log<\/p>\n<h3>\u7b2c\u5341\u6b65&#xff1a;\u9ad8\u7ea7\u6280\u5de7\u4e0e\u81ea\u52a8\u5316<\/h3>\n<h4>SSH\u8df3\u677f\u673a\u914d\u7f6e<\/h4>\n<p><span class=\"token comment\"># ~\/.ssh\/config<\/span><br \/>\nHost jumphost<br \/>\n    HostName jump.example.com<br \/>\n    User jumpuser<\/p>\n<p>Host target<br \/>\n    HostName target.internal.com<br \/>\n    User targetuser<br \/>\n    ProxyJump jumphost<\/p>\n<p><span class=\"token comment\"># \u6216\u8005\u4f7f\u7528ProxyCommand<\/span><br \/>\nHost target2<br \/>\n    HostName target2.internal.com<br \/>\n    User targetuser<br \/>\n    ProxyCommand <span class=\"token function\">ssh<\/span> -W %h:%p jumphost<\/p>\n<h4>\u6279\u91cf\u670d\u52a1\u5668\u7ba1\u7406<\/h4>\n<p><span class=\"token shebang important\">#!\/bin\/bash<\/span><br \/>\n<span class=\"token comment\"># batch_ssh.sh &#8211; \u6279\u91cf\u6267\u884cSSH\u547d\u4ee4<\/span><\/p>\n<p><span class=\"token assign-left variable\">SERVERS<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token string\">&#034;server1.example.com&#034;<\/span><br \/>\n    <span class=\"token string\">&#034;server2.example.com&#034;<\/span><br \/>\n    <span class=\"token string\">&#034;server3.example.com&#034;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token assign-left variable\">COMMAND<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;uptime&#034;<\/span><\/p>\n<p><span class=\"token keyword\">for<\/span> <span class=\"token for-or-select variable\">server<\/span> <span class=\"token keyword\">in<\/span> <span class=\"token string\">&#034;<span class=\"token variable\">${SERVERS<span class=\"token punctuation\">[<\/span>&#064;<span class=\"token punctuation\">]<\/span>}<\/span>&#034;<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">do<\/span><br \/>\n    <span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;Executing on <span class=\"token variable\">$server<\/span>:&#034;<\/span><br \/>\n    <span class=\"token function\">ssh<\/span> ubuntu&#064;<span class=\"token variable\">$server<\/span> <span class=\"token string\">&#034;<span class=\"token variable\">$COMMAND<\/span>&#034;<\/span><br \/>\n    <span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;&#8212;&#034;<\/span><br \/>\n<span class=\"token keyword\">done<\/span><\/p>\n<h4>SSH\u4f1a\u8bdd\u7ba1\u7406<\/h4>\n<p><span class=\"token comment\"># \u4f7f\u7528screen\u7ba1\u7406SSH\u4f1a\u8bdd<\/span><br \/>\n<span class=\"token function\">screen<\/span> -S ssh_session<br \/>\n<span class=\"token function\">ssh<\/span> username&#064;server<br \/>\n<span class=\"token comment\"># Ctrl&#043;A, D \u5206\u79bb\u4f1a\u8bdd<\/span><br \/>\n<span class=\"token function\">screen<\/span> -r ssh_session  <span class=\"token comment\"># \u91cd\u65b0\u8fde\u63a5<\/span><\/p>\n<p><span class=\"token comment\"># \u4f7f\u7528tmux\u7ba1\u7406SSH\u4f1a\u8bdd<\/span><br \/>\ntmux new-session -s ssh_session<br \/>\n<span class=\"token function\">ssh<\/span> username&#064;server<br \/>\n<span class=\"token comment\"># Ctrl&#043;B, D \u5206\u79bb\u4f1a\u8bdd<\/span><br \/>\ntmux attach-session -t ssh_session  <span class=\"token comment\"># \u91cd\u65b0\u8fde\u63a5<\/span><\/p>\n<h3>\u5b9e\u9645\u5e94\u7528\u6848\u4f8b&#xff1a;Python Web\u5e94\u7528\u90e8\u7f72<\/h3>\n<h4>\u5b8c\u6574\u7684\u90e8\u7f72\u6d41\u7a0b<\/h4>\n<p><span class=\"token comment\"># 1. \u51c6\u5907\u5de5\u4f5c<\/span><br \/>\n<span class=\"token comment\"># \u751f\u6210\u90e8\u7f72\u5bc6\u94a5<\/span><br \/>\nssh-keygen -t ed25519 -f ~\/.ssh\/deploy_key -C <span class=\"token string\">&#034;deploy&#064;myapp.com&#034;<\/span><\/p>\n<p><span class=\"token comment\"># \u914d\u7f6eSSH<\/span><br \/>\n<span class=\"token function\">cat<\/span> <span class=\"token operator\">&gt;&gt;<\/span> ~\/.ssh\/config <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">EOF<br \/>\nHost myapp-prod<br \/>\n    HostName prod.myapp.com<br \/>\n    User deploy<br \/>\n    Port 22<br \/>\n    IdentityFile ~\/.ssh\/deploy_key<br \/>\n    ServerAliveInterval 60<br \/>\n    ServerAliveCountMax 3<br \/>\nEOF<\/span><\/p>\n<p><span class=\"token comment\"># 2. \u90e8\u7f72\u516c\u94a5<\/span><br \/>\nssh-copy-id -i ~\/.ssh\/deploy_key myapp-prod<\/p>\n<p><span class=\"token comment\"># 3. \u521b\u5efa\u90e8\u7f72\u811a\u672c<\/span><br \/>\n<span class=\"token function\">cat<\/span> <span class=\"token operator\">&gt;<\/span> deploy.sh <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#039;EOF&#039;<br \/>\n#!\/bin\/bash<br \/>\nset -e<\/p>\n<p>SERVER&#061;&#034;myapp-prod&#034;<br \/>\nAPP_DIR&#061;&#034;\/opt\/myapp&#034;<br \/>\nVENV_DIR&#061;&#034;$APP_DIR\/venv&#034;<\/p>\n<p>echo &#034;&#x1f680; Starting deployment&#8230;&#034;<\/p>\n<p># \u5907\u4efd\u5f53\u524d\u7248\u672c<br \/>\necho &#034;&#x1f4e6; Creating backup&#8230;&#034;<br \/>\nssh $SERVER &#034;sudo tar -czf \/opt\/backups\/myapp_$(date &#043;%Y%m%d_%H%M%S).tar.gz $APP_DIR&#034;<\/p>\n<p># \u4e0a\u4f20\u4ee3\u7801<br \/>\necho &#034;&#x1f4e4; Uploading code&#8230;&#034;<br \/>\nrsync -avz &#8211;delete \\\\<br \/>\n    &#8211;exclude&#061;&#039;.git&#039; \\\\<br \/>\n    &#8211;exclude&#061;&#039;__pycache__&#039; \\\\<br \/>\n    &#8211;exclude&#061;&#039;*.pyc&#039; \\\\<br \/>\n    &#8211;exclude&#061;&#039;venv\/&#039; \\\\<br \/>\n    &#8211;exclude&#061;&#039;.env&#039; \\\\<br \/>\n    .\/ $SERVER:$APP_DIR\/<\/p>\n<p># \u5b89\u88c5\u4f9d\u8d56<br \/>\necho &#034;&#x1f4e6; Installing dependencies&#8230;&#034;<br \/>\nssh $SERVER &#034;cd $APP_DIR &amp;&amp; source $VENV_DIR\/bin\/activate &amp;&amp; pip install -r requirements.txt&#034;<\/p>\n<p># \u8fd0\u884c\u6d4b\u8bd5<br \/>\necho &#034;&#x1f9ea; Running tests&#8230;&#034;<br \/>\nssh $SERVER &#034;cd $APP_DIR &amp;&amp; source $VENV_DIR\/bin\/activate &amp;&amp; python -m pytest tests\/&#034;<\/p>\n<p># \u6570\u636e\u5e93\u8fc1\u79fb<br \/>\necho &#034;&#x1f5c4;\ufe0f Running database migrations&#8230;&#034;<br \/>\nssh $SERVER &#034;cd $APP_DIR &amp;&amp; source $VENV_DIR\/bin\/activate &amp;&amp; python manage.py migrate&#034;<\/p>\n<p># \u6536\u96c6\u9759\u6001\u6587\u4ef6<br \/>\necho &#034;&#x1f4c1; Collecting static files&#8230;&#034;<br \/>\nssh $SERVER &#034;cd $APP_DIR &amp;&amp; source $VENV_DIR\/bin\/activate &amp;&amp; python manage.py collectstatic &#8211;noinput&#034;<\/p>\n<p># \u91cd\u542f\u670d\u52a1<br \/>\necho &#034;&#x1f504; Restarting services&#8230;&#034;<br \/>\nssh $SERVER &#034;sudo systemctl restart myapp&#034;<br \/>\nssh $SERVER &#034;sudo systemctl restart nginx&#034;<\/p>\n<p># \u68c0\u67e5\u670d\u52a1\u72b6\u6001<br \/>\necho &#034;\u2705 Checking service status&#8230;&#034;<br \/>\nssh $SERVER &#034;sudo systemctl status myapp &#8211;no-pager&#034;<\/p>\n<p># \u5065\u5eb7\u68c0\u67e5<br \/>\necho &#034;&#x1f3e5; Health check&#8230;&#034;<br \/>\nsleep 5<br \/>\nHEALTH_STATUS&#061;$(ssh $SERVER &#034;curl -f -s http:\/\/localhost:8000\/health\/ || echo &#039;FAILED&#039;&#034;)<br \/>\nif [ &#034;$HEALTH_STATUS&#034; &#061; &#034;FAILED&#034; ]; then<br \/>\n    echo &#034;\u274c Health check failed!&#034;<br \/>\n    exit 1<br \/>\nfi<\/p>\n<p>echo &#034;&#x1f389; Deployment completed successfully!&#034;<br \/>\nEOF<\/span><\/p>\n<p><span class=\"token function\">chmod<\/span> &#043;x deploy.sh<\/p>\n<h3>\u5e38\u89c1\u95ee\u9898\u89e3\u7b54<\/h3>\n<h4>Q1: SSH\u8fde\u63a5\u7ecf\u5e38\u65ad\u5f00\u600e\u4e48\u529e&#xff1f;<\/h4>\n<p>A: \u914d\u7f6e\u5fc3\u8df3\u5305\u4fdd\u6301\u8fde\u63a5&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u5728 ~\/.ssh\/config \u4e2d\u6dfb\u52a0<\/span><br \/>\nServerAliveInterval <span class=\"token number\">60<\/span><br \/>\nServerAliveCountMax <span class=\"token number\">3<\/span><\/p>\n<h4>Q2: \u5982\u4f55\u7ba1\u7406\u591a\u4e2aSSH\u5bc6\u94a5&#xff1f;<\/h4>\n<p>A: \u4f7f\u7528SSH\u914d\u7f6e\u6587\u4ef6\u4e3a\u4e0d\u540c\u670d\u52a1\u5668\u6307\u5b9a\u4e0d\u540c\u5bc6\u94a5&#xff1a;<\/p>\n<p>Host server1<br \/>\n    IdentityFile ~\/.ssh\/server1_key<br \/>\nHost server2<br \/>\n    IdentityFile ~\/.ssh\/server2_key<\/p>\n<h4>Q3: \u5fd8\u8bb0SSH\u5bc6\u94a5\u5bc6\u7801\u600e\u4e48\u529e&#xff1f;<\/h4>\n<p>A:<\/p>\n<li>\u5982\u679c\u8bb0\u5f97\u5bc6\u7801&#xff0c;\u53ef\u4ee5\u66f4\u6539&#xff1a;ssh-keygen -p -f ~\/.ssh\/id_rsa<\/li>\n<li>\u5982\u679c\u5fd8\u8bb0\u5bc6\u7801&#xff0c;\u9700\u8981\u91cd\u65b0\u751f\u6210\u5bc6\u94a5\u5bf9\u5e76\u91cd\u65b0\u90e8\u7f72<\/li>\n<h4>Q4: \u5982\u4f55\u5728Windows\u4e0a\u4f7f\u7528SSH&#xff1f;<\/h4>\n<p>A:<\/p>\n<li>\u4f7f\u7528Windows 10\u5185\u7f6e\u7684OpenSSH\u5ba2\u6237\u7aef<\/li>\n<li>\u4f7f\u7528PuTTY\u5de5\u5177<\/li>\n<li>\u4f7f\u7528WSL&#xff08;Windows Subsystem for Linux&#xff09;<\/li>\n<h3>\u603b\u7ed3<\/h3>\n<p>SSH\u662f\u73b0\u4ee3\u670d\u52a1\u5668\u7ba1\u7406\u7684\u6838\u5fc3\u5de5\u5177&#xff0c;\u638c\u63e1\u5b83\u5c31\u50cf\u638c\u63e1\u4e86\u670d\u52a1\u5668\u4e16\u754c\u7684\u4e07\u80fd\u94a5\u5319\u3002\u901a\u8fc7\u672c\u6587\u7684\u5b66\u4e60&#xff0c;\u4f60\u5df2\u7ecf\u638c\u63e1\u4e86&#xff1a;<\/p>\n<li>SSH\u57fa\u7840\u6982\u5ff5&#xff1a;\u7406\u89e3SSH\u7684\u5de5\u4f5c\u539f\u7406\u548c\u5b89\u5168\u673a\u5236<\/li>\n<li>\u5bc6\u94a5\u8ba4\u8bc1&#xff1a;\u544a\u522b\u5bc6\u7801&#xff0c;\u4f7f\u7528\u66f4\u5b89\u5168\u7684\u5bc6\u94a5\u8ba4\u8bc1<\/li>\n<li>\u914d\u7f6e\u7ba1\u7406&#xff1a;\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u7b80\u5316\u8fde\u63a5\u7ba1\u7406<\/li>\n<li>\u6587\u4ef6\u4f20\u8f93&#xff1a;\u638c\u63e1SCP\u3001SFTP\u3001RSYNC\u7684\u4f7f\u7528<\/li>\n<li>\u7aef\u53e3\u8f6c\u53d1&#xff1a;\u5b9e\u73b0\u590d\u6742\u7684\u7f51\u7edc\u8bbf\u95ee\u9700\u6c42<\/li>\n<li>\u5b89\u5168\u5b9e\u8df5&#xff1a;\u4fdd\u62a4SSH\u8fde\u63a5\u7684\u5b89\u5168\u6027<\/li>\n<li>\u81ea\u52a8\u5316\u90e8\u7f72&#xff1a;\u5c06SSH\u96c6\u6210\u5230Python\u9879\u76ee\u90e8\u7f72\u6d41\u7a0b<\/li>\n<p>\u8bb0\u4f4f&#xff0c;SSH\u4e0d\u4ec5\u4ec5\u662f\u4e00\u4e2a\u8fde\u63a5\u5de5\u5177&#xff0c;\u5b83\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u8fdc\u7a0b\u7ba1\u7406\u89e3\u51b3\u65b9\u6848\u3002\u719f\u7ec3\u638c\u63e1SSH\u5c06\u5927\u5927\u63d0\u5347\u4f60\u7684\u670d\u52a1\u5668\u7ba1\u7406\u6548\u7387\u548c\u5b89\u5168\u6027\u3002<\/p>\n<h3>\u4e0b\u4e00\u6b65\u5b66\u4e60\u5efa\u8bae<\/h3>\n<li>\u6df1\u5165\u5b66\u4e60&#xff1a;SSH\u96a7\u9053\u3001\u7aef\u53e3\u8f6c\u53d1\u7684\u9ad8\u7ea7\u5e94\u7528<\/li>\n<li>\u81ea\u52a8\u5316\u5de5\u5177&#xff1a;\u7ed3\u5408Ansible\u5b9e\u73b0\u6279\u91cf\u670d\u52a1\u5668\u7ba1\u7406<\/li>\n<li>\u76d1\u63a7\u96c6\u6210&#xff1a;SSH\u8fde\u63a5\u76d1\u63a7\u548c\u65e5\u5fd7\u5206\u6790<\/li>\n<li>\u5b89\u5168\u52a0\u56fa&#xff1a;SSH\u871c\u7f50\u3001\u5165\u4fb5\u68c0\u6d4b\u7cfb\u7edf<\/li>\n<li>\u4e91\u539f\u751f&#xff1a;\u5728Kubernetes\u73af\u5883\u4e2d\u7684SSH\u5e94\u7528<\/li>\n<h3>\u53c2\u8003\u8d44\u6599<\/h3>\n<ul>\n<li>OpenSSH\u5b98\u65b9\u6587\u6863<\/li>\n<li>SSH\u914d\u7f6e\u6700\u4f73\u5b9e\u8df5<\/li>\n<li>Paramiko Python\u5e93\u6587\u6863<\/li>\n<li>SSH\u5b89\u5168\u52a0\u56fa\u6307\u5357<\/li>\n<\/ul>\n<p>\u672c\u6587\u662f&#034;\u670d\u52a1\u5668\u4e0e\u90e8\u7f72&#034;\u7cfb\u5217\u7684\u7b2c\u4e8c\u7bc7&#xff0c;\u4e0b\u4e00\u7bc7\u6211\u4eec\u5c06\u63a2\u8ba8systemd\u670d\u52a1\u7ba1\u7406&#xff0c;\u5b66\u4e60\u5982\u4f55\u8ba9Python\u5e94\u7528\u5728\u670d\u52a1\u5668\u4e0a\u7a33\u5b9a\u8fd0\u884c\u3002\u5982\u679c\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u6709\u5e2e\u52a9&#xff0c;\u8bf7\u70b9\u8d5e\u6536\u85cf&#xff0c;\u5e76\u5173\u6ce8\u6211\u4eec\u7684\u540e\u7eed\u66f4\u65b0&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf29\u6b21\u3002\u672c\u6587\u901a\u8fc7\u8d39\u66fc\u5b66\u4e60\u6cd5\uff0c\u4ece\u96f6\u5f00\u59cb\u8be6\u89e3SSH\u8fdc\u7a0b\u670d\u52a1\u5668\u7ba1\u7406\u7684\u6838\u5fc3\u6280\u672f\u3002\u4ece\u57fa\u7840\u8fde\u63a5\u5230\u9ad8\u7ea7\u914d\u7f6e\uff0c\u4ece\u5bc6\u7801\u8ba4\u8bc1\u5230\u5bc6\u94a5\u7ba1\u7406\uff0c\u4ece\u6587\u4ef6\u4f20\u8f93\u5230\u7aef\u53e3\u8f6c\u53d1\uff0c\u5168\u9762\u638c\u63e1SSH\u8fd9\u4e2a\u670d\u52a1\u5668\u7ba1\u7406\u795e\u5668\u3002\u901a\u8fc7\u751f\u52a8\u7684\u7c7b\u6bd4\u548c\u5b9e\u9645\u6848\u4f8b\uff0c\u8ba9\u4f60\u5f7b\u5e95\u7406\u89e3SSH\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u5e76\u5b66\u4f1a\u5728Python\u9879\u76ee\u90e8\u7f72\u4e2d\u9ad8\u6548\u4f7f\u7528SSH\u8fdb\u884c\u8fdc\u7a0b\u7ba1\u7406\u3002<\/p>\n","protected":false},"author":2,"featured_media":46139,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[77,61,4392,43,782],"topic":[],"class_list":["post-46141","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-ssh","tag-61","tag-4392","tag-43","tag-782"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u670d\u52a1\u5668\u4e0e\u90e8\u7f72 02\u3011SSH\u8fdc\u7a0b\u7ba1\u7406\u795e\u5668\uff1a\u544a\u522b\u5bc6\u7801\uff0c\u62e5\u62b1\u5b89\u5168\u9ad8\u6548\u7684\u670d\u52a1\u5668\u8fde\u63a5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/46141.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u670d\u52a1\u5668\u4e0e\u90e8\u7f72 02\u3011SSH\u8fdc\u7a0b\u7ba1\u7406\u795e\u5668\uff1a\u544a\u522b\u5bc6\u7801\uff0c\u62e5\u62b1\u5b89\u5168\u9ad8\u6548\u7684\u670d\u52a1\u5668\u8fde\u63a5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf29\u6b21\u3002\u672c\u6587\u901a\u8fc7\u8d39\u66fc\u5b66\u4e60\u6cd5\uff0c\u4ece\u96f6\u5f00\u59cb\u8be6\u89e3SSH\u8fdc\u7a0b\u670d\u52a1\u5668\u7ba1\u7406\u7684\u6838\u5fc3\u6280\u672f\u3002\u4ece\u57fa\u7840\u8fde\u63a5\u5230\u9ad8\u7ea7\u914d\u7f6e\uff0c\u4ece\u5bc6\u7801\u8ba4\u8bc1\u5230\u5bc6\u94a5\u7ba1\u7406\uff0c\u4ece\u6587\u4ef6\u4f20\u8f93\u5230\u7aef\u53e3\u8f6c\u53d1\uff0c\u5168\u9762\u638c\u63e1SSH\u8fd9\u4e2a\u670d\u52a1\u5668\u7ba1\u7406\u795e\u5668\u3002\u901a\u8fc7\u751f\u52a8\u7684\u7c7b\u6bd4\u548c\u5b9e\u9645\u6848\u4f8b\uff0c\u8ba9\u4f60\u5f7b\u5e95\u7406\u89e3SSH\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u5e76\u5b66\u4f1a\u5728Python\u9879\u76ee\u90e8\u7f72\u4e2d\u9ad8\u6548\u4f7f\u7528SSH\u8fdb\u884c\u8fdc\u7a0b\u7ba1\u7406\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/46141.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T18:32:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729183243-688913cbf1fe9.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46141.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/46141.html\",\"name\":\"\u3010\u670d\u52a1\u5668\u4e0e\u90e8\u7f72 02\u3011SSH\u8fdc\u7a0b\u7ba1\u7406\u795e\u5668\uff1a\u544a\u522b\u5bc6\u7801\uff0c\u62e5\u62b1\u5b89\u5168\u9ad8\u6548\u7684\u670d\u52a1\u5668\u8fde\u63a5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T18:32:45+00:00\",\"dateModified\":\"2025-07-29T18:32:45+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/46141.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/46141.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46141.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u670d\u52a1\u5668\u4e0e\u90e8\u7f72 02\u3011SSH\u8fdc\u7a0b\u7ba1\u7406\u795e\u5668\uff1a\u544a\u522b\u5bc6\u7801\uff0c\u62e5\u62b1\u5b89\u5168\u9ad8\u6548\u7684\u670d\u52a1\u5668\u8fde\u63a5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010\u670d\u52a1\u5668\u4e0e\u90e8\u7f72 02\u3011SSH\u8fdc\u7a0b\u7ba1\u7406\u795e\u5668\uff1a\u544a\u522b\u5bc6\u7801\uff0c\u62e5\u62b1\u5b89\u5168\u9ad8\u6548\u7684\u670d\u52a1\u5668\u8fde\u63a5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/46141.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u670d\u52a1\u5668\u4e0e\u90e8\u7f72 02\u3011SSH\u8fdc\u7a0b\u7ba1\u7406\u795e\u5668\uff1a\u544a\u522b\u5bc6\u7801\uff0c\u62e5\u62b1\u5b89\u5168\u9ad8\u6548\u7684\u670d\u52a1\u5668\u8fde\u63a5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf29\u6b21\u3002\u672c\u6587\u901a\u8fc7\u8d39\u66fc\u5b66\u4e60\u6cd5\uff0c\u4ece\u96f6\u5f00\u59cb\u8be6\u89e3SSH\u8fdc\u7a0b\u670d\u52a1\u5668\u7ba1\u7406\u7684\u6838\u5fc3\u6280\u672f\u3002\u4ece\u57fa\u7840\u8fde\u63a5\u5230\u9ad8\u7ea7\u914d\u7f6e\uff0c\u4ece\u5bc6\u7801\u8ba4\u8bc1\u5230\u5bc6\u94a5\u7ba1\u7406\uff0c\u4ece\u6587\u4ef6\u4f20\u8f93\u5230\u7aef\u53e3\u8f6c\u53d1\uff0c\u5168\u9762\u638c\u63e1SSH\u8fd9\u4e2a\u670d\u52a1\u5668\u7ba1\u7406\u795e\u5668\u3002\u901a\u8fc7\u751f\u52a8\u7684\u7c7b\u6bd4\u548c\u5b9e\u9645\u6848\u4f8b\uff0c\u8ba9\u4f60\u5f7b\u5e95\u7406\u89e3SSH\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u5e76\u5b66\u4f1a\u5728Python\u9879\u76ee\u90e8\u7f72\u4e2d\u9ad8\u6548\u4f7f\u7528SSH\u8fdb\u884c\u8fdc\u7a0b\u7ba1\u7406\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/46141.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T18:32:45+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250729183243-688913cbf1fe9.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"10 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/46141.html","url":"https:\/\/www.wsisp.com\/helps\/46141.html","name":"\u3010\u670d\u52a1\u5668\u4e0e\u90e8\u7f72 02\u3011SSH\u8fdc\u7a0b\u7ba1\u7406\u795e\u5668\uff1a\u544a\u522b\u5bc6\u7801\uff0c\u62e5\u62b1\u5b89\u5168\u9ad8\u6548\u7684\u670d\u52a1\u5668\u8fde\u63a5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T18:32:45+00:00","dateModified":"2025-07-29T18:32:45+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/46141.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/46141.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/46141.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u670d\u52a1\u5668\u4e0e\u90e8\u7f72 02\u3011SSH\u8fdc\u7a0b\u7ba1\u7406\u795e\u5668\uff1a\u544a\u522b\u5bc6\u7801\uff0c\u62e5\u62b1\u5b89\u5168\u9ad8\u6548\u7684\u670d\u52a1\u5668\u8fde\u63a5"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=46141"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46141\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/46139"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=46141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=46141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=46141"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=46141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}