{"id":1585,"date":"2023-03-25T19:31:49","date_gmt":"2023-03-25T11:31:49","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1585"},"modified":"2023-04-27T21:29:49","modified_gmt":"2023-04-27T13:29:49","slug":"resolve-issue-of-centos-hosts-in-vagrant-being-unable-to-ssh-remote-connections","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/resolve-issue-of-centos-hosts-in-vagrant-being-unable-to-ssh-remote-connections\/","title":{"rendered":"\u89e3\u51b3Vagrant\u4e2d\u7684CentOS\u4e3b\u673a\u65e0\u6cd5ssh\u8fdc\u7a0b\u8fde\u63a5\u7684\u95ee\u9898"},"content":{"rendered":"<h2>\u95ee\u9898\u63cf\u8ff0<\/h2>\n<p>Vagrant\u5b8c\u6210\u865a\u62df\u673a\u642d\u5efa\uff0c\u5e76\u914d\u7f6e\u597d\u7f51\u7edc\u540e\uff0c\u76f4\u63a5\u901a\u8fc7<code>ssh vagrant@172.16.10.10 -p 22<\/code>\uff08\u8fd9\u91cc\u4f7f\u7528\u81ea\u5df1\u914d\u7f6e\u7684\u79c1\u6709\u7f51\u7edcip\uff09\u767b\u5f55\u865a\u62df\u673a\uff0c\u62a5\u9519<\/p>\n<pre><code>Permission denied (publickey,gssapi-keyex,gssapi-with-mic).<\/code><\/pre>\n<p><!-- more --><\/p>\n<p>\u4f7f\u7528\u5728\u672c\u673a\u6620\u5c04\u76842222\u7aef\u53e3\uff0c<code>ssh vagrant@127.0.0.1 -p 2222<\/code>\u767b\u5f55\uff1a<\/p>\n<pre><code>Permission denied (publickey,gssapi-keyex,gssapi-with-mic).<\/code><\/pre>\n<p>Xshell\u7b49\u5de5\u5177\u4e5f\u8fde\u63a5\u4e0d\u4e0a<\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p>\u8fd9\u91cc\u7684\u7aef\u53e3<code>2222<\/code>\u662f<code>vagrant up<\/code>\u7684\u65f6\u5019\uff0c<code>vagrant<\/code>\u81ea\u52a8\u5c06\u865a\u62df\u673a\u7684<code>22<\/code>\u7aef\u53e3\u6620\u5c04\u5230\u7684\u5bbf\u4e3b\u673a\u7684<code>2222<\/code>\u4e0a\uff0c\u8bbf\u95ee\u5bbf\u4e3b\u673a\u7684<code>2222<\/code>\u5c31\u662f\u8bbf\u95ee\u865a\u62df\u673a\u7684<code>22<\/code>\u7aef\u53e3<\/p>\n<p>\u865a\u62df\u673a\u6620\u5c04\u51fa\u6765\u7684\u7aef\u53e3\u662f<code>vagrant<\/code>\u751f\u6210\u7684\uff0c\u4e0d\u56fa\u5b9a\uff0c\u6ce8\u610f\u4e00\u4e0b<code>vagrant up<\/code>\u65f6\u7684\u542f\u52a8\u4fe1\u606f\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7<code>vagrant ssh-config<\/code>\u6765\u67e5\u770b\u6620\u5c04\u7684\u7aef\u53e3<\/p>\n<h3>\u79d8\u94a5\u767b\u5f55<\/h3>\n<p>\u9ed8\u8ba4\u65e0\u6cd5\u901a\u8fc7\u7528\u6237\u540d\u5bc6\u7801\u767b\u5f55\uff0c\u53ea\u80fd\u4f7f\u7528\u79d8\u94a5\u767b\u5f55\u3002\u9996\u5148\u5728\u5de5\u4f5c\u76ee\u5f55\u4e0b\u67e5\u770bssh\u4fe1\u606f\u3002<\/p>\n<pre><code>> vagrant ssh-config\nHost default\n  HostName 127.0.0.1\n  User vagrant\n  Port 2200\n  UserKnownHostsFile \/dev\/null\n  StrictHostKeyChecking no\n  PasswordAuthentication no\n  IdentityFile E:\/Vagrant\/CentOS7-2\/.vagrant\/machines\/default\/virtualbox\/private_key\n  IdentitiesOnly yes\n  LogLevel FATAL<\/code><\/pre>\n<p><code>IdentityFile<\/code>\u5bf9\u5e94\u7684\u5c31\u662fssh\u79c1\u94a5\u5730\u5740\uff0c\u7136\u540e\u914d\u7f6e\u4e0b\u79c1\u94a5\u5373\u53ef\u767b\u5f55\u3002<\/p>\n<h3>\u8d26\u53f7\u5bc6\u7801\u767b\u5f55<\/h3>\n<p>\u4ece\u5b98\u65b9\u7ad9\u70b9\u4e0b\u8f7d\u7684<code>centos\/7<\/code>\u8fd9\u4e2a box \u9ed8\u8ba4\u662f\u5173\u95ed\u4e86\u8d26\u53f7\u5bc6\u7801\u767b\u5f55\u7684\uff0c\u901a\u8fc7<code>vagrant ssh<\/code>\u8fde\u63a5\u5230\u865a\u62df\u673a\uff0c\u7136\u540e\u53bb\u7f16\u8f91<code>\/etc\/ssh\/sshd_config<\/code>\uff0c\u5c06<code>PasswordAuthentication<\/code>\u7684\u503c\u4fee\u6539\u4e3a<code>yes<\/code><\/p>\n<p><code>\/etc\/ssh\/sshd_config<\/code>\u6587\u4ef6<code>vagrant<\/code>\u7528\u6237\u662f\u770b\u4e0d\u5230\u7684\uff0c\u9700\u8981\u4f7f\u7528<code>sudo vi \/etc\/ssh\/sshd_config<\/code>\u547d\u4ee4\u53bb\u7f16\u8f91<\/p>\n<p>\u4fee\u6539\u5b8c\u6210\u540e\uff0c\u91cd\u542f<code>sshd<\/code>\u670d\u52a1\uff1a<code>systemctl restart sshd<\/code><\/p>\n<p>\u5373\u53ef\u901a\u8fc7\u8d26\u6237\u5bc6\u7801\u767b\u5f55<\/p>\n<h3>root\u767b\u5f55<\/h3>\n<p>\u540c\u8d26\u53f7\u5bc6\u7801\u767b\u5f55\uff0c\u7f16\u8f91<code>\/etc\/ssh\/sshd_config<\/code>\uff0c\u5c06<code>PermitRootLogin<\/code>\u7684\u503c\u4fee\u6539\u4e3a<code>yes<\/code><\/p>\n<p>\u4fee\u6539\u5b8c\u6210\u540e\uff0c\u91cd\u542f<code>sshd<\/code>\u670d\u52a1\uff1a<code>systemctl restart sshd<\/code><\/p>\n<p>\u5373\u53ef\u901a\u8fc7root\u767b\u5f55<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u63cf\u8ff0 Vagrant\u5b8c\u6210\u865a\u62df\u673a\u642d\u5efa\uff0c\u5e76\u914d\u7f6e\u597d\u7f51\u7edc\u540e\uff0c\u76f4\u63a5\u901a\u8fc7ssh vagrant@172.16.10.1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[96,139],"class_list":["post-1585","post","type-post","status-publish","format-standard","hentry","category-devops-base","tag-ssh","tag-vagrant"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1585"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1585\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}