{"id":1020,"date":"2022-10-23T18:51:37","date_gmt":"2022-10-23T09:51:37","guid":{"rendered":"https:\/\/rfsec.ddns.net\/db\/?p=1020"},"modified":"2022-10-29T08:08:04","modified_gmt":"2022-10-28T23:08:04","slug":"wsl%e5%86%85%e3%81%ae%e3%82%b5%e3%83%bc%e3%83%90%e3%81%b8%e5%a4%96%e9%83%a8pc%e3%81%8b%e3%82%89%e6%8e%a5%e7%b6%9a","status":"publish","type":"post","link":"https:\/\/rfsec.ddns.net\/db\/?p=1020","title":{"rendered":"WSL\u5185\u306e\u30b5\u30fc\u30d0\u3078\u5916\u90e8PC\u304b\u3089\u63a5\u7d9a"},"content":{"rendered":"\n<p><strong>ssh service\u306e\u81ea\u52d5\u8d77\u52d5\u8a2d\u5b9a<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/buzz-server.com\/tech\/ubuntu-ssh\/\">https:\/\/buzz-server.com\/tech\/ubuntu-ssh\/<\/a><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>echo &#39;none none rc defaults 0 0&#39; | sudo tee -a \/etc\/fstab\necho &#39;#!\/bin\/bash&#39; | sudo tee \/sbin\/mount.rc\necho &#39;sudo service ssh start&#39; | sudo tee -a \/sbin\/mount.rc\nsudo chmod +x \/sbin\/mount.rc<\/code><\/pre><\/div>\n\n\n\n<p>$sudo ssh-keygen -A \u3092\u5b9f\u884c<\/p>\n\n\n\n<p>password\u8a8d\u8a3c\u3092\u6709\u52b9\u306b\u3059\u308b\u306b\u306f\u3001\/etc\/ssh\/sshd_config\u3092\u4fee\u6b63\u3059\u308b\u3002<\/p>\n\n\n\n<p><strong>\u30dd\u30fc\u30c8\u8ee2\u9001\u306e\u8a2d\u5b9aPowerShell \u30b9\u30af\u30ea\u30d7\u30c8<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/neos21.net\/blog\/2021\/07\/20-01.html\">https:\/\/neos21.net\/blog\/2021\/07\/20-01.html<\/a><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(&quot;Administrators&quot;)) { Start-Process powershell.exe &quot;-File `&quot;$PSCommandPath`&quot;&quot; -Verb RunAs; exit }\n\n$ip = bash.exe -c &quot;ip r |tail -n1|cut -d &#39; &#39; -f9&quot;\nif( ! $ip ){\n  echo &quot;The Script Exited, the ip address of WSL 2 cannot be found&quot;;\n  exit;\n}\n\n# All the ports you want to forward separated by comma\n$ports=@(22,8501,8888);\n$ports_a = $ports -join &quot;,&quot;;\n\n# Remove Firewall Exception Rules\niex &quot;Remove-NetFireWallRule -DisplayName &#39;WSL 2 Firewall Unlock&#39; &quot;;\n\n# Adding Exception Rules for inbound and outbound Rules\niex &quot;New-NetFireWallRule -DisplayName &#39;WSL 2 Firewall Unlock&#39; -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP&quot;;\niex &quot;New-NetFireWallRule -DisplayName &#39;WSL 2 Firewall Unlock&#39; -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP&quot;;\n\nfor( $i = 0; $i -lt $ports.length; $i++ ){\n  $port = $ports[$i];\n  iex &quot;netsh interface portproxy add v4tov4 listenport=$port listenaddress=* connectport=$port connectaddress=$ip&quot;;\n}\n\n# Show proxies\niex &quot;netsh interface portproxy show v4tov4&quot;;\n<\/code><\/pre><\/div>\n\n\n\n<p><strong>\u30dd\u30fc\u30c8\u8ee2\u9001\u306e\u524a\u9664<\/strong>\u3000\u3000netsh.exe interface portproxy delete v4tov4 listenport=22<\/p>\n\n\n\n<p><strong>Windows FireWall\u306e\u8a2d\u5b9a\uff08\u89e3\u653e\uff09<\/strong><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/qiita.com\/DR623G\/items\/20e1d95e25e4ae658a33\" target=\"_blank\">https:\/\/qiita.com\/DR623G\/items\/20e1d95e25e4ae658a33<\/a><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>netsh advfirewall firewall add rule name=&quot;WSL2&quot; dir=in action=allow protocol=TCP localport=22<\/code><\/pre><\/div>\n\n\n\n<p>\u8a2d\u5b9a\u306e\u78ba\u8a8d<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>netsh advfirewall firewall show rule name=&quot;WSL2&quot; verbose<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>ssh service\u306e\u81ea\u52d5\u8d77\u52d5\u8a2d\u5b9a https:\/\/buzz-server.com\/tech\/ubuntu-ssh\/ $sudo ssh-keygen -A \u3092\u5b9f\u884c password\u8a8d\u8a3c\u3092\u6709\u52b9\u306b\u3059\u308b\u306b\u306f\u3001\/etc\/ss [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1020","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"featured_image_src":null,"author_info":{"display_name":"mars","author_link":"https:\/\/rfsec.ddns.net\/db\/?author=1"},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/1020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1020"}],"version-history":[{"count":7,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/1020\/revisions"}],"predecessor-version":[{"id":1045,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/1020\/revisions\/1045"}],"wp:attachment":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}