{"id":219584,"date":"2021-05-31T08:11:56","date_gmt":"2021-05-31T00:11:56","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=219584"},"modified":"2021-05-25T15:12:22","modified_gmt":"2021-05-25T07:12:22","slug":"debug-ssh-connections","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/debug-ssh-connections.html","title":{"rendered":"\u5982\u4f55\u8c03\u8bd5SSH\u8fde\u63a5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u672c\u6587\u5c06\u4ecb\u7ecd\u4e00\u4e9b\u53ef\u7528\u4e8e\u8bca\u65adSSH\u8fde\u63a5\u7684\u5feb\u901f\u65b9\u6cd5\u548c\u6280\u672f\uff0c\u5305\u62ec\u4f55\u65f6\u65e0\u6cd5\u8fde\u63a5SSH\uff0c\u8eab\u4efd\u9a8c\u8bc1\u9519\u8bef\u7b49\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u95ee\u9898\u4e00\uff1aSSH\u670d\u52a1\u6ca1\u6709\u8fd0\u884c<\/strong><\/div>\n

SSH\u8fde\u63a5\u9519\u8bef\u7684\u5e38\u89c1\u539f\u56e0\u662f\u670d\u52a1\u672a\u5728\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u8fd0\u884c\u3002\u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u670d\u52a1\u610f\u5916\u5173\u95ed\u6216\u7cfb\u7edf\u91cd\u65b0\u542f\u52a8\u540e\u670d\u52a1\u672a\u542f\u52a8\u800c\u5f15\u8d77\u7684\u3002<\/p>\n

\u8981\u68c0\u67e5SSH\u670d\u52a1\u662f\u5426\u6b63\u5728\u8fd0\u884c\uff0c\u8bf7\u8fd0\u884c\u4e0b\u9762\u547d\u4ee4\uff1a<\/p>\n

\r\n[root@server1 ~]# systemctl status sshd\r\n<\/pre>\n

\"\"<\/p>\n

\u89e3\u51b3\u65b9\u6cd5<\/strong><\/span><\/div>\n

\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8bbe\u7f6eSSH\u670d\u52a1\u5f00\u673a\u542f\u52a8\uff0c\u5e76\u542f\u52a8\u670d\u52a1\uff1a<\/p>\n

\r\n[root@server1 ~]# systemctl enable sshd\r\n[root@server1 ~]# systemctl start sshd\r\n<\/pre>\n
\u95ee\u9898\u4e8c\uff1a\u975e\u6807\u51c6\u7aef\u53e3\u4e0a\u7684SSH<\/strong><\/div>\n

\u8c03\u8bd5SSH\u8fde\u63a5\u65f6\u7684\u7b2c\u4e8c\u4e2a\u5e38\u89c1\u95ee\u9898\u662f\u4f7f\u7528\u975e\u6807\u51c6\u7aef\u53e3\u3002\u5982\u679cSSH\u5728\u9ed8\u8ba4\u7aef\u53e322\u4ee5\u5916\u7684\u5176\u4ed6\u7aef\u53e3\u4e0a\u8fd0\u884c\uff0c\u5219\u9664\u975e\u660e\u786e\u6307\u5b9a\u8fd0\u884cSSH\u7684\u7aef\u53e3\uff0c\u5426\u5219\u5c06\u4e0d\u80fd\u8fde\u63a5\u5230\u8fdc\u7a0b\u4e3b\u673a\u3002<\/p>\n

\u8981\u67e5\u770b\u8fd0\u884cSSH\u7684\u7aef\u53e3\uff0c\u8bf7\u4f7f\u7528netstat\u4e4b\u7c7b\u7684\u5de5\u5177\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

\r\n[root@clean-idea-1 ~]# netstat -tlunp|grep sshd\r\ntcp        0      0 0.0.0.0:28159           0.0.0.0:*               LISTEN      818\/sshd            \r\ntcp6       0      0 :::28159                :::*                    LISTEN      818\/sshd            \r\n<\/pre>\n

\"\"
\n\u4e0a\u9762\u7684\u8f93\u51fa\u663e\u793a\u4e86SSH\u670d\u52a1\u5728\u54ea\u4e2a\u7aef\u53e3\u4e0a\u8fd0\u884c\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5b83\u662f\u7aef\u53e328159\u3002<\/p>\n

\u89e3\u51b3\u65b9\u6cd5<\/strong><\/span><\/div>\n

\u7aef\u53e3\u4e0d\u662f\u9ed8\u8ba4\u768422\u65f6\uff0c\u8fde\u63a5\u5c31\u9700\u8981\u6307\u5b9a\u7aef\u53e3\u4e86\uff1a<\/p>\n

\r\n[root@server1 ~]# ssh root@192.168.43.131 -p 28159\r\n<\/pre>\n
\u95ee\u9898\u4e09\uff1a\u7aef\u53e3\u88ab\u5360\u7528<\/strong><\/div>\n

SSH\u8fde\u63a5\u9519\u8bef\u7684\u53e6\u4e00\u4e2a\u539f\u56e0\u662f\u5176\u4ed6\u670d\u52a1\u6216\u8fdb\u7a0b\u662f\u5426\u4e5f\u4f7f\u7528\u4e0eSSH\u670d\u52a1\u76f8\u540c\u7684\u7aef\u53e3\u3002\u4f8b\u5982\uff0cSSH\u7684\u7aef\u53e3\u53f7\u4e3a80\uff0c\u8fd9\u548chttp\u670d\u52a1\u7684\u7aef\u53e3\u51b2\u7a81\u4e86\uff0c\u5219\u7c7b\u4f3cApache\u7684\u670d\u52a1\u53ef\u80fd\u6b63\u5728\u4f7f\u7528\u76f8\u540c\u7684\u7aef\u53e3\u3002<\/p>\n

\u8981\u67e5\u770b\u5176\u4ed6\u8fdb\u7a0b\u662f\u5426\u6b63\u5728\u4f7f\u7528\u4e0eSSH\u76f8\u540c\u7684\u7aef\u53e3\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\u65e5\u5fd7\uff1a<\/p>\n

\r\n[root@server1 ~]# journalctl -t sshd\r\n<\/pre>\n

\u8be5\u547d\u4ee4\u5e94\u8fd4\u56de\u5982\u4e0b\u6240\u793a\u7684\u9519\u8bef\uff0c\u663e\u793a\u7aef\u53e3\u5df2\u88ab\u5360\u7528\u3002
\n\"\"<\/p>\n

\u89e3\u51b3\u65b9\u6cd5<\/strong><\/span><\/div>\n

\u5728\u8fd9\u53ef\u4ee5\u4fee\u6539ssh\u7684\u7aef\u53e3\u53f7\uff0c\u6253\u5f00\u914d\u7f6e\u6587\u4ef6\u5c06\u7aef\u53e3\u4fee\u6539\u4e3a\u5176\u4ed6\u7684\uff0cPort 2222<\/code><\/p>\n

\r\nvim \/etc\/ssh\/sshd_config \r\n\r\nPort 2222\r\n<\/pre>\n

\"\"<\/p>\n

\u95ee\u9898\u56db\uff1a\u88ab\u9632\u706b\u5899\u963b\u6b62<\/strong><\/div>\n

\u5982\u679c\u5c1d\u8bd5\u4e86\u4e0a\u8ff0\u6240\u6709\u65b9\u6cd5\uff0c\u4ecd\u65e0\u6cd5\u5efa\u7acbSSH\u8fde\u63a5\uff0c\u5219\u53ef\u4ee5\u770b\u770b\u9632\u706b\u5899\u662f\u5426\u963b\u6b62\u8fde\u63a5\uff1f<\/p>\n

\u89e3\u51b3\u65b9\u6cd5<\/strong><\/span><\/div>\n

\u5728Cetnos8\u4e2d\uff0c\u4f7f\u7528fireawlld\u67e5\u770b\u9632\u706b\u5899\uff0c\u5e76\u5c06\u7aef\u53e3\u6dfb\u52a0\u5141\u8bb8\u91cc\u9762\uff1a<\/p>\n

\r\n[root@server1 ~]# firewall-cmd --list-all\r\n[root@server1 ~]# firewall-cmd --permanent --add-port=2222\/tcp\r\nsuccess\r\n[root@server1 ~]# firewall-cmd --reload\r\nsuccess\r\n<\/pre>\n

\"\"<\/p>\n

\u95ee\u9898\u4e94\uff1a\u5df2\u7981\u7528\u5bc6\u7801\u767b\u5f55<\/strong><\/div>\n

\u6709\u65f6\uff0c\u60a8\u53ef\u4ee5\u5c06SSH\u914d\u7f6e\u4e3a\u4e0d\u63a5\u53d7\u5bc6\u7801\u767b\u5f55\uff0c\u800c\u4ec5\u4f7f\u7528\u516c\u5bc6\u94a5\u8eab\u4efd\u9a8c\u8bc1\u3002\u5982\u679c\u516c\u94a5\u5728\u670d\u52a1\u5668\u4e0a\u4e0d\u53ef\u7528\u6216\u7f3a\u5c11\u79c1\u94a5\u5bf9\uff0c\u5219\u53ef\u80fd\u5bfc\u81f4\u4e0d\u80fd\u767b\u5f55\u7684\u95ee\u9898\u3002<\/p>\n

\u89e3\u51b3\u65b9\u6cd5<\/strong><\/span><\/div>\n

\u8981\u68c0\u67e5\/etc\/ssh\/sshd_config<\/code>\u914d\u7f6e\u6587\u4ef6\u662f\u5426\u5141\u8bb8\u5bc6\u7801\u767b\u5f55\uff0c\u8bf7\u5c06ssh\u914d\u7f6e\u8bbe\u7f6e\u4e3a\u5982\u4e0b\uff1a<\/p>\n

\r\n[root@server1 ~]# grep PasswordAuthentication \/etc\/ssh\/sshd_config \r\n#PasswordAuthentication yes\r\nPasswordAuthentication yes\r\n# PasswordAuthentication.  Depending on your PAM configuration,\r\n# PAM authentication, then enable this but set PasswordAuthentication\r\n<\/pre>\n

\u4e0a\u9762\u7684\u8f93\u51fa\u663e\u793a\u5141\u8bb8\u5bc6\u7801\u767b\u5f55\u3002<\/p>\n

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

\u672c\u6587\u8ba8\u8bba\u4e86SSH\u8fde\u63a5\u9519\u8bef\u7684\u4e3b\u8981\u539f\u56e0\u4ee5\u53ca\u5982\u4f55\u89e3\u51b3\u5b83\u4eec\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

SSH\u8fde\u63a5\u9519\u8bef\u7684\u5e38\u89c1\u539f\u56e0\u662f\u670d\u52a1\u672a\u5728\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u8fd0\u884c\u3002\u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u670d\u52a1\u610f\u5916\u5173\u95ed\u6216\u7cfb\u7edf\u91cd\u65b0\u542f\u52a8\u540e\u670d\u52a1\u672a\u542f\u52a8\u800c\u5f15\u8d77\u7684 […]<\/p>\n","protected":false},"author":309,"featured_media":219585,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-219584","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\/219584","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\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=219584"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219584\/revisions"}],"predecessor-version":[{"id":219591,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219584\/revisions\/219591"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/219585"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=219584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=219584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=219584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}