{"id":145158,"date":"2019-05-24T08:12:58","date_gmt":"2019-05-24T00:12:58","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=145158"},"modified":"2019-05-20T10:15:00","modified_gmt":"2019-05-20T02:15:00","slug":"linux-ssh-hostname","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-ssh-hostname.html","title":{"rendered":"\u5728 Linux \u4e2d\u521b\u5efa SSH \u522b\u540d"},"content":{"rendered":"
\u5982\u679c\u4f60\u7ecf\u5e38\u901a\u8fc7 SSH \u8bbf\u95ee\u8bb8\u591a\u4e0d\u540c\u7684\u8fdc\u7a0b\u7cfb\u7edf\uff0c\u8fd9\u4e2a\u6280\u5de7\u5c06\u4e3a\u4f60\u8282\u7701\u4e00\u4e9b\u65f6\u95f4\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7 SSH \u4e3a\u9891\u7e41\u8bbf\u95ee\u7684\u7cfb\u7edf\u521b\u5efa SSH \u522b\u540d\uff0c\u8fd9\u6837\u4f60\u5c31\u4e0d\u5fc5\u8bb0\u4f4f\u6240\u6709\u4e0d\u540c\u7684\u7528\u6237\u540d\u3001\u4e3b\u673a\u540d\u3001SSH \u7aef\u53e3\u53f7\u548c IP \u5730\u5740\u7b49\u3002\u6b64\u5916\uff0c\u5b83\u907f\u514d\u4e86\u5728 SSH \u5230 Linux \u670d\u52a1\u5668\u65f6\u91cd\u590d\u8f93\u5165\u76f8\u540c\u7684\u7528\u6237\u540d\u3001\u4e3b\u673a\u540d\u3001IP \u5730\u5740\u3001\u7aef\u53e3\u53f7\u3002<\/p>\n
\u5728\u6211\u77e5\u9053\u8fd9\u4e2a\u6280\u5de7\u4e4b\u524d\uff0c\u6211\u901a\u5e38\u4f7f\u7528\u4ee5\u4e0b\u4efb\u610f\u4e00\u79cd\u65b9\u5f0f\u901a\u8fc7 SSH \u8fde\u63a5\u5230\u8fdc\u7a0b\u7cfb\u7edf\u3002<\/p>\n
\u4f7f\u7528 IP \u5730\u5740\uff1a<\/p>\n
$ ssh 192.168.225.22<\/pre>\n\u6216\u4f7f\u7528\u7aef\u53e3\u53f7\u3001\u7528\u6237\u540d\u548c IP \u5730\u5740\uff1a<\/p>\n
$ ssh -p 22 sk@192.168.225.22<\/pre>\n\u6216\u4f7f\u7528\u7aef\u53e3\u53f7\u3001\u7528\u6237\u540d\u548c\u4e3b\u673a\u540d\uff1a<\/p>\n
$ ssh -p 22 sk@server.example.com<\/pre>\n\u8fd9\u91cc<\/p>\n
\u6211\u76f8\u4fe1\u5927\u591a\u6570 Linux \u65b0\u624b\u548c\uff08\u6216\u4e00\u4e9b\uff09\u7ba1\u7406\u5458\u90fd\u4f1a\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u901a\u8fc7 SSH \u8fde\u63a5\u5230\u8fdc\u7a0b\u7cfb\u7edf\u3002\u4f46\u662f\uff0c\u5982\u679c\u4f60\u901a\u8fc7 SSH \u8fde\u63a5\u5230\u591a\u4e2a\u4e0d\u540c\u7684\u7cfb\u7edf\uff0c\u8bb0\u4f4f\u6240\u6709\u4e3b\u673a\u540d\u6216 IP \u5730\u5740\uff0c\u8fd8\u6709\u7528\u6237\u540d\u662f\u56f0\u96be\u7684\uff0c\u9664\u975e\u4f60\u5c06\u5b83\u4eec\u5199\u5728\u7eb8\u4e0a\u6216\u8005\u5c06\u5176\u4fdd\u5b58\u5728\u6587\u672c\u6587\u4ef6\u4e2d\u3002\u522b\u62c5\u5fc3\uff01\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4e3a SSH \u8fde\u63a5\u521b\u5efa\u522b\u540d\uff08\u6216\u5feb\u6377\u65b9\u5f0f\uff09\u8f7b\u677e\u89e3\u51b3\u3002<\/p>\n
\u6211\u4eec\u53ef\u4ee5\u7528\u4e24\u79cd\u65b9\u6cd5\u4e3a SSH \u547d\u4ee4\u521b\u5efa\u522b\u540d\u3002<\/p>\n
\u8fd9\u662f\u6211\u521b\u5efa\u522b\u540d\u7684\u9996\u9009\u65b9\u6cd5\u3002<\/p>\n
\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 SSH \u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u6765\u521b\u5efa SSH \u522b\u540d\u3002\u4e3a\u6b64\uff0c\u7f16\u8f91 ~\/.ssh\/config \u6587\u4ef6\uff08\u5982\u679c\u6b64\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u53ea\u9700\u521b\u5efa\u4e00\u4e2a\uff09\uff1a<\/p>\n
$ vi ~\/.ssh\/config\r\n\u6dfb\u52a0\u6240\u6709\u8fdc\u7a0b\u4e3b\u673a\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/pre>\nHost webserver\r\n HostName 192.168.225.22\r\n User sk\r\n\r\nHost dns\r\n HostName server.example.com\r\n User root\r\n\r\nHost dhcp\r\n HostName 192.168.225.25\r\n User ostechnix\r\n Port 2233<\/pre>\n<\/p>\n
\u4f7f\u7528 SSH \u914d\u7f6e\u6587\u4ef6\u5728 Linux \u4e2d\u521b\u5efa SSH \u522b\u540d<\/em><\/span><\/p>\n
\u5c06 Host\u3001Hostname\u3001User \u548c Port \u914d\u7f6e\u7684\u503c\u66ff\u6362\u4e3a\u4f60\u81ea\u5df1\u7684\u503c\u3002\u6dfb\u52a0\u6240\u6709\u8fdc\u7a0b\u4e3b\u673a\u7684\u8be6\u7ec6\u4fe1\u606f\u540e\uff0c\u4fdd\u5b58\u5e76\u9000\u51fa\u8be5\u6587\u4ef6\u3002<\/p>\n
\u73b0\u5728\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u901a\u8fc7 SSH \u8fdb\u5165\u7cfb\u7edf\uff1a<\/p>\n
$ ssh webserver\r\n$ ssh dns\r\n$ ssh dhcp<\/pre>\n\u5c31\u662f\u8fd9\u4e48\u7b80\u5355!<\/p>\n
\u770b\u770b\u4e0b\u9762\u7684\u622a\u56fe\u3002<\/p>\n
<\/p>\n
\u4f7f\u7528 SSH \u522b\u540d\u8bbf\u95ee\u8fdc\u7a0b\u7cfb\u7edf<\/em><\/span><\/p>\n
\u770b\u5230\u4e86\u5417\uff1f\u6211\u53ea\u4f7f\u7528\u522b\u540d\uff08\u4f8b\u5982 webserver\uff09\u6765\u8bbf\u95ee IP \u5730\u5740\u4e3a 192.168.225.22 \u7684\u8fdc\u7a0b\u7cfb\u7edf\u3002<\/p>\n
\u8bf7\u6ce8\u610f\uff0c\u8fd9\u53ea\u4f7f\u7528\u4e8e\u5f53\u524d\u7528\u6237\u3002\u5982\u679c\u8981\u4e3a\u6240\u6709\u7528\u6237\uff08\u7cfb\u7edf\u8303\u56f4\u5185\uff09\u63d0\u4f9b\u522b\u540d\uff0c\u8bf7\u5728 \/etc\/ssh\/ssh_config \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0a\u884c\u3002<\/p>\n
\u4f60\u8fd8\u53ef\u4ee5\u5728 SSH \u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u8bb8\u591a\u5176\u4ed6\u5185\u5bb9\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u5df2\u914d\u7f6e\u57fa\u4e8e SSH \u5bc6\u94a5\u7684\u8eab\u4efd\u9a8c\u8bc1\uff0c\u8bf4\u660e SSH \u5bc6\u94a5\u6587\u4ef6\u7684\u4f4d\u7f6e\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n
Host ubuntu\r\nHostName 192.168.225.50\r\nUser senthil\r\nIdentityFIle ~\/.ssh\/id_rsa_remotesystem\r\n\u786e\u4fdd\u5df2\u4f7f\u7528\u4f60\u81ea\u5df1\u7684\u503c\u66ff\u6362\u4e3b\u673a\u540d\u3001\u7528\u6237\u540d\u548c SSH \u5bc6\u94a5\u6587\u4ef6\u8def\u5f84\u3002<\/pre>\n\u73b0\u5728\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\uff1a<\/p>\n
$ ssh ubuntu<\/pre>\n\u8fd9\u6837\uff0c\u4f60\u53ef\u4ee5\u6dfb\u52a0\u5e0c\u671b\u901a\u8fc7 SSH \u8bbf\u95ee\u7684\u4efb\u610f\u591a\u53f0\u8fdc\u7a0b\u4e3b\u673a\uff0c\u5e76\u4f7f\u7528\u522b\u540d\u5feb\u901f\u8bbf\u95ee\u5b83\u4eec\u3002<\/p>\n
\u65b9\u6cd5 2 \u2013 \u4f7f\u7528 Bash \u522b\u540d<\/strong><\/span><\/div>\n\u8fd9\u662f\u521b\u5efa SSH \u522b\u540d\u7684\u4e00\u79cd\u5e94\u6025\u53d8\u901a\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u52a0\u5feb\u901a\u4fe1\u7684\u901f\u5ea6\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 alias \u547d\u4ee4\u4f7f\u8fd9\u9879\u4efb\u52a1\u66f4\u5bb9\u6613\u3002<\/p>\n
\u6253\u5f00 ~\/.bashrc \u6216\u8005 ~\/.bash_profile \u6587\u4ef6\uff1a<\/p>\n
alias webserver='ssh sk@server.example.com'\r\nalias dns='ssh sk@server.example.com'\r\nalias dhcp='ssh sk@server.example.com -p 2233'\r\nalias ubuntu='ssh sk@server.example.com -i ~\/.ssh\/id_rsa_remotesystem'\r\n\u518d\u6b21\u786e\u4fdd\u4f60\u5df2\u4f7f\u7528\u81ea\u5df1\u7684\u503c\u66ff\u6362\u4e3b\u673a\u3001\u4e3b\u673a\u540d\u3001\u7aef\u53e3\u53f7\u548c IP \u5730\u5740\u3002\u4fdd\u5b58\u6587\u4ef6\u5e76\u9000\u51fa\u3002<\/pre>\n\u7136\u540e\uff0c\u4f7f\u7528\u547d\u4ee4\u5e94\u7528\u66f4\u6539\uff1a<\/p>\n
$ source ~\/.bashrc\r\n\u6216\u8005<\/pre>\n$ source ~\/.bash_profile\r\n\u5728\u6b64\u65b9\u6cd5\u4e2d\uff0c\u4f60\u751a\u81f3\u4e0d\u9700\u8981\u4f7f\u7528 ssh \u522b\u540d \u547d\u4ee4\u3002\u76f8\u53cd\uff0c\u53ea\u9700\u4f7f\u7528\u522b\u540d\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/pre>\n$ webserver\r\n$ dns\r\n$ dhcp\r\n$ ubuntu<\/pre>\n<\/p>\n
\u8fd9\u4e24\u79cd\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u4f46\u5bf9\u4e8e\u7ecf\u5e38\u901a\u8fc7 SSH \u8fde\u63a5\u5230\u591a\u4e2a\u4e0d\u540c\u7cfb\u7edf\u7684\u4eba\u6765\u8bf4\u975e\u5e38\u6709\u7528\uff0c\u800c\u4e14\u975e\u5e38\u65b9\u4fbf\u3002\u4f7f\u7528\u9002\u5408\u4f60\u7684\u4e0a\u8ff0\u4efb\u4f55\u4e00\u79cd\u65b9\u6cd5\uff0c\u901a\u8fc7 SSH \u5feb\u901f\u8bbf\u95ee\u8fdc\u7a0b Linux \u7cfb\u7edf\u3002<\/p>\n
\u5efa\u8bae\u9605\u8bfb\uff1a<\/p>\n
\n
- \u5141\u8bb8\u6216\u62d2\u7edd SSH \u8bbf\u95ee Linux \u4e2d\u7684\u7279\u5b9a\u7528\u6237\u6216\u7ec4<\/li>\n
- \u5982\u4f55\u5728 Linux \u4e0a SSH \u5230\u7279\u5b9a\u76ee\u5f55<\/li>\n
- \u5982\u4f55\u5728 Linux \u4e2d\u65ad\u5f00 SSH \u4f1a\u8bdd<\/li>\n
- 4 \u79cd\u65b9\u5f0f\u5728\u9000\u51fa SSH \u4f1a\u8bdd\u540e\u4fdd\u6301\u547d\u4ee4\u8fd0\u884c<\/li>\n
- SSLH \u2013 \u5171\u4eab\u76f8\u540c\u7aef\u53e3\u7684 HTTPS \u548c SSH<\/li>\n<\/ul>\n
\u76ee\u524d\u8fd9\u5c31\u662f\u5168\u90e8\u4e86\uff0c\u5e0c\u671b\u5b83\u5bf9\u4f60\u6709\u5e2e\u52a9\u3002\u66f4\u591a\u597d\u4e1c\u897f\u8981\u6765\u4e86\uff0c\u656c\u8bf7\u5173\u6ce8\uff01<\/p>\n
\u5e72\u676f\uff01<\/p>\n
\nvia: https:\/\/www.ostechnix.com\/how-to-create-ssh-alias-in-linux\/<\/a><\/p>\n
\u4f5c\u8005\uff1ask<\/a> \u9009\u9898\uff1alujun9972<\/a> \u8bd1\u8005\uff1aMjSeven<\/a> \u6821\u5bf9\uff1awxy<\/a><\/p>\n
\u672c\u6587\u7531 LCTT<\/a> \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a> \u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5982\u679c\u4f60\u7ecf\u5e38\u901a\u8fc7 SSH \u8bbf\u95ee\u8bb8\u591a\u4e0d\u540c\u7684\u8fdc\u7a0b\u7cfb\u7edf\uff0c\u8fd9\u4e2a\u6280\u5de7\u5c06\u4e3a\u4f60\u8282\u7701\u4e00\u4e9b\u65f6\u95f4\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7 SSH \u4e3a\u9891\u7e41\u8bbf\u95ee\u7684\u7cfb […]<\/p>\n","protected":false},"author":323,"featured_media":109834,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-145158","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\/145158","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\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=145158"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/145158\/revisions"}],"predecessor-version":[{"id":145338,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/145158\/revisions\/145338"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/109834"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=145158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=145158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=145158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}