{"id":42293,"date":"2023-07-05T04:35:41","date_gmt":"2023-03-13T10:55:18","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/"},"modified":"2024-04-30T12:03:06","modified_gmt":"2024-04-30T04:03:06","slug":"%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/","title":{"rendered":"\u66f4\u6539Vagrant\u7684\u767b\u5f55\u7528\u6237"},"content":{"rendered":"<ol>\u521b\u5efa\u7528\u6237\u5e76\u8bbe\u7f6e\u516c\u94a5\u3002<\/ol>\n<ul class=\"post-ul\">\u30e6\u30fc\u30b6\u4f5c\u6210<\/ul>\n<pre class=\"post-pre\"><code>$ vagrant ssh\r\n\r\n$ sudo -s\r\n# useradd -m ansible\r\n<\/code><\/pre>\n<ul class=\"post-ul\">sudo\u306e\u8a2d\u5b9a<\/ul>\n<pre class=\"post-pre\"><code># cp -p \/etc\/sudoers.d\/{vagrant,ansible}\r\n# sed -e 's\/vagrant\/ansible\/g' \/etc\/sudoers.d\/ansible\r\nansible ALL=(ALL) NOPASSWD:ALL\r\n# sed -i 's\/vagrant\/ansible\/g' \/etc\/sudoers.d\/ansible\r\n<\/code><\/pre>\n<ul class=\"post-ul\">\u516c\u958b\u9375\u306e\u8a2d\u7f6e<\/ul>\n<pre class=\"post-pre\"><code>## scp\u7528\u306bconfig\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\r\n$ vagrant ssh-config &gt; vagrant_sshconfig\r\n\r\n## VM\u5185\u306b\u30b3\u30d4\u30fc\r\n$ scp -F vagrant_sshconfig \/Users\/tshu1\/.ssh\/id_ed25519_ansible.pub default:~\/\r\n\r\n## VM\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u3001\u516c\u958b\u9375\u3092\u8a2d\u7f6e\u3059\u308b\r\n# mkdir \/home\/ansible\/.ssh &amp;&amp; chmod 700 \/home\/ansible\/.ssh\r\n# mv id_ed25519_ansible.pub \/home\/ansible\/.ssh\/authorized_keys\r\n# chmod 400 \/home\/ansible\/.ssh\/authorized_keys &amp;&amp; chown -R ansible:ansible \/home\/ansible\r\n\r\n# ls -laR \/home\/ansible\/\r\n\/home\/ansible\/:\r\ntotal 24\r\ndrwxr-xr-x 3 ansible ansible 4096 Jan  3 03:10 .\r\ndrwxr-xr-x 5 root    root    4096 Jan  3 03:09 ..\r\n-rw-r--r-- 1 ansible ansible  220 Feb 25  2020 .bash_logout\r\n-rw-r--r-- 1 ansible ansible 3771 Feb 25  2020 .bashrc\r\n-rw-r--r-- 1 ansible ansible  807 Feb 25  2020 .profile\r\ndrwx------ 2 ansible ansible 4096 Jan  3 03:11 .ssh\r\n\r\n\/home\/ansible\/.ssh:\r\ntotal 12\r\ndrwx------ 2 ansible ansible 4096 Jan  3 03:11 .\r\ndrwxr-xr-x 3 ansible ansible 4096 Jan  3 03:10 ..\r\n-r-------- 1 ansible ansible  103 Jan  3 03:05 authorized_keys\r\n<\/code><\/pre>\n<ol>Vagrantfile\u7684\u4fee\u6539<\/ol>\n<pre class=\"post-pre\"><code><span class=\"gh\">diff --git a\/Vagrantfile b\/Vagrantfile\r\nindex 259ec02..78b6909 100644\r\n<\/span><span class=\"gd\">--- a\/Vagrantfile\r\n<\/span><span class=\"gi\">+++ b\/Vagrantfile\r\n<\/span><span class=\"p\">@@ -1,3 +1,5 @@<\/span>\r\n Vagrant.configure(\"2\") do |config|\r\n   config.vm.box = \"ubuntu\/focal64\"\r\n<span class=\"gi\">+  config.ssh.username = \"ansible\"\r\n+  config.ssh.private_key_path = \"\/Users\/tshu1\/.ssh\/id_ed25519_ansible\"\r\n<\/span> end\r\n\r\n<\/code><\/pre>\n<ul class=\"post-ul\">reload\u306e\u5b9f\u65bd<\/ul>\n<pre class=\"post-pre\"><code>$ vagrant reload\r\n==&gt; default: Attempting graceful shutdown of VM...\r\n==&gt; default: Checking if box 'ubuntu\/focal64' version '20201210.0.0' is up to date...\r\n==&gt; default: Clearing any previously set forwarded ports...\r\n==&gt; default: Clearing any previously set network interfaces...\r\n==&gt; default: Preparing network interfaces based on configuration...\r\n    default: Adapter 1: nat\r\n==&gt; default: Forwarding ports...\r\n    default: 22 (guest) =&gt; 2222 (host) (adapter 1)\r\n==&gt; default: Running 'pre-boot' VM customizations...\r\n==&gt; default: Booting VM...\r\n==&gt; default: Waiting for machine to boot. This may take a few minutes...\r\n    default: SSH address: 127.0.0.1:2222\r\n    default: SSH username: ansible\r\n    default: SSH auth method: private key\r\n    default: Warning: Connection reset. Retrying...\r\n    default: Warning: Remote connection disconnect. Retrying...\r\n==&gt; default: Machine booted and ready!\r\n[default] GuestAdditions 6.1.16 running --- OK.\r\n==&gt; default: Checking for guest additions in VM...\r\n==&gt; default: Mounting shared folders...\r\n    default: \/vagrant =&gt; \/Users\/tshu1\/ghq\/github.com\/tshu1\/ubuntu-2004\r\n==&gt; default: Machine already provisioned. Run `vagrant provision` or use the `--provision`\r\n==&gt; default: flag to force provisioning. Provisioners marked to run always will still run.\r\n<\/code><\/pre>\n<ol>\u767b\u5f55\u786e\u8ba4<\/ol>\n<pre class=\"post-pre\"><code>$ vagrant ssh\r\nWelcome to Ubuntu 20.04.1 LTS (GNU\/Linux 5.4.0-54-generic x86_64)\r\n\r\n * Documentation:  https:\/\/help.ubuntu.com\r\n * Management:     https:\/\/landscape.canonical.com\r\n * Support:        https:\/\/ubuntu.com\/advantage\r\n\r\n  System information as of Sun Jan  3 03:27:19 UTC 2021\r\n\r\n  System load:  0.05              Processes:               119\r\n  Usage of \/:   4.2% of 38.71GB   Users logged in:         0\r\n  Memory usage: 18%               IPv4 address for enp0s3: 10.0.2.15\r\n  Swap usage:   0%\r\n\r\n\r\n12 updates can be installed immediately.\r\n8 of these updates are security updates.\r\nTo see these additional updates run: apt list --upgradable\r\n\r\n\r\n$ id\r\nuid=1002(ansible) gid=1002(ansible) groups=1002(ansible)\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u521b\u5efa\u7528\u6237\u5e76\u8bbe\u7f6e\u516c\u94a5\u3002 \u30e6\u30fc\u30b6\u4f5c\u6210 $ vagrant ssh $ sudo -s # useradd -m a [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-42293","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u66f4\u6539Vagrant\u7684\u767b\u5f55\u7528\u6237 - Blog - Silicon Cloud<\/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.silicloud.com\/zh\/blog\/\u66f4\u6539vagrant\u7684\u767b\u5f55\u7528\u6237\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u66f4\u6539Vagrant\u7684\u767b\u5f55\u7528\u6237\" \/>\n<meta property=\"og:description\" content=\"\u521b\u5efa\u7528\u6237\u5e76\u8bbe\u7f6e\u516c\u94a5\u3002 \u30e6\u30fc\u30b6\u4f5c\u6210 $ vagrant ssh $ sudo -s # useradd -m a [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u66f4\u6539vagrant\u7684\u767b\u5f55\u7528\u6237\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-13T10:55:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-30T04:03:06+00:00\" \/>\n<meta name=\"author\" content=\"\u6e05, \u5b87\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6e05, \u5b87\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/\",\"name\":\"\u66f4\u6539Vagrant\u7684\u767b\u5f55\u7528\u6237 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-03-13T10:55:18+00:00\",\"dateModified\":\"2024-04-30T04:03:06+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u66f4\u6539Vagrant\u7684\u767b\u5f55\u7528\u6237\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e\",\"name\":\"\u6e05, \u5b87\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g\",\"caption\":\"\u6e05, \u5b87\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u66f4\u6539Vagrant\u7684\u767b\u5f55\u7528\u6237 - Blog - Silicon Cloud","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.silicloud.com\/zh\/blog\/\u66f4\u6539vagrant\u7684\u767b\u5f55\u7528\u6237\/","og_locale":"zh_CN","og_type":"article","og_title":"\u66f4\u6539Vagrant\u7684\u767b\u5f55\u7528\u6237","og_description":"\u521b\u5efa\u7528\u6237\u5e76\u8bbe\u7f6e\u516c\u94a5\u3002 \u30e6\u30fc\u30b6\u4f5c\u6210 $ vagrant ssh $ sudo -s # useradd -m a [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u66f4\u6539vagrant\u7684\u767b\u5f55\u7528\u6237\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-03-13T10:55:18+00:00","article_modified_time":"2024-04-30T04:03:06+00:00","author":"\u6e05, \u5b87","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u5b87","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/","name":"\u66f4\u6539Vagrant\u7684\u767b\u5f55\u7528\u6237 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-03-13T10:55:18+00:00","dateModified":"2024-04-30T04:03:06+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u66f4\u6539Vagrant\u7684\u767b\u5f55\u7528\u6237"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e","name":"\u6e05, \u5b87","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g","caption":"\u6e05, \u5b87"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e6%9b%b4%e6%94%b9vagrant%e7%9a%84%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=42293"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42293\/revisions"}],"predecessor-version":[{"id":91798,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42293\/revisions\/91798"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=42293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=42293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=42293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}