{"id":34663,"date":"2019-10-31T21:59:41","date_gmt":"2019-10-31T18:59:41","guid":{"rendered":"https:\/\/prohoster.info\/blog\/podklyuchenie-k-windows-po-ssh-kak-v-linux\/"},"modified":"2019-10-31T21:59:41","modified_gmt":"2019-10-31T18:59:41","slug":"podklyuchenie-k-windows-po-ssh-kak-v-linux","status":"publish","type":"post","link":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/podklyuchenie-k-windows-po-ssh-kak-v-linux","title":{"rendered":"Connecting to Windows via SSH like in Linux","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p>I've always found it frustrating to connect to Windows machines. No, I'm not against Microsoft or their products. Every product exists for its purpose, but that's not the issue here.<br \/>\nI have always dreadfully struggled to connect to Windows servers because these connections are either configured in the most convoluted way (hello WinRM with HTTPS) or are not very stable (hello RDP to virtual machines across the ocean).<\/p>\n<p>Therefore, having accidentally stumbled upon the project <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/PowerShell\/Win32-OpenSSH\">Win32-OpenSSH<\/a><\/noindex>, I decided to share my setup experience. This tool may save someone a lot of nerves.<\/p>\n<p><img decoding=\"async\" alt=\"Connecting to Windows via SSH like in Linux\" src=\"\/wp-content\/uploads\/2019\/05\/0f42089eb1cac646e11eaa841a1eb26d.png\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><br \/>\nInstallation options:<\/p>\n<ol>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/PowerShell\/Win32-OpenSSH\/wiki\/Install-Win32-OpenSSH\">Manually<\/a><\/noindex><\/li>\n<li>Through <noindex><a rel=\"nofollow\" href=\"https:\/\/chocolatey.org\/packages\/openssh\">the package<\/a><\/noindex> Chocolatey<\/li>\n<li>Via Ansible, for example, the role <noindex><a rel=\"nofollow\" href=\"https:\/\/galaxy.ansible.com\/jborean93\/win_openssh\">jborean93.win_openssh<\/a><\/noindex><\/li>\n<\/ol>\n<p>\nNext, I will discuss the first point, as the others are relatively straightforward.<\/p>\n<p>Note that this project is still in beta, so it is not recommended for production use.<\/p>\n<p>So, let\u2019s download the latest release, which is currently <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/PowerShell\/Win32-OpenSSH\/releases\/tag\/v7.9.0.0p1-Beta\">7.9.0.0p1-beta<\/a><\/noindex>. There are versions for both 32-bit and 64-bit systems.<\/p>\n<p>Unpack it to <i>C:Program FilesOpenSSH<\/i><br \/>\nA crucial moment for proper operation: write permissions in this directory must only be for <i>SYSTEM<\/i> and the admin group.<\/p>\n<p>Install the services using the script <i>install-sshd.ps1<\/i> located in this directory<\/p>\n<pre><code class=\"plaintext\">powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1<\/code><\/pre>\n<p>\nAllow incoming connections on port 22:<\/p>\n<pre><code class=\"plaintext\">New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22<\/code><\/pre>\n<p>\nClarification: the applet <i>New-NetFirewallRule<\/i> is used on Windows Server 2012 and newer. In older systems (or desktop versions), you can use the command:<\/p>\n<pre><code class=\"plaintext\">netsh advfirewall firewall add rule name=sshd dir=in action=allow protocol=TCP localport=22\n<\/code><\/pre>\n<p>\nStarting the service:<\/p>\n<pre><code class=\"plaintext\">net start sshd<\/code><\/pre>\n<p>\nUpon startup, host keys will be automatically generated (if they are missing) in <i>%programdata%ssh<\/i><\/p>\n<p>To enable service auto-start with system startup, we can use the command:<\/p>\n<pre><code class=\"plaintext\">Set-Service sshd -StartupType Automatic<\/code><\/pre>\n<p>\nAdditionally, you can change the default shell (after installation, by default it's <i>cmd<\/i>):<\/p>\n<pre><code class=\"plaintext\">New-ItemProperty -Path \"HKLM:SOFTWAREOpenSSH\" -Name DefaultShell -Value \"C:WindowsSystem32WindowsPowerShellv1.0powershell.exe\" -PropertyType String -Force<\/code><\/pre>\n<p>\nClarification: You must specify the absolute path.<\/p>\n<p>What's next?<\/p>\n<p>Then we adjust <i>sshd_config<\/i>, located in <i>C:ProgramDatassh<\/i>. For example:<\/p>\n<pre><code class=\"plaintext\">PasswordAuthentication no\nPubkeyAuthentication yes<\/code><\/pre>\n<p>\nAnd create the directory <i>.ssh<\/i>, and within it, the file <i>authorized_keys<\/i>. Here, we will write the public keys.<\/p>\n<p>An important clarification: write permissions to this file must be granted only to the user whose directory contains the file.<\/p>\n<p>However, if you have issues with this, you can always disable rights checking in the config:<\/p>\n<pre><code class=\"plaintext\">StrictModes no<\/code><\/pre>\n<p>\nBy the way, in <i>C:Program FilesOpenSSH<\/i> there are 2 scripts (<i>FixHostFilePermissions.ps1<\/i>, <i>FixUserFilePermissions.ps1<\/i>), which are supposed to but not necessarily fix permissions, including those with <i>authorized_keys<\/i>, but for some reason, they do not fix.<\/p>\n<p>Don't forget to restart the service <i>sshd.<\/i> after applying the changes.<\/p>\n<pre><code class=\"bash\">ru-mbp-666:infrastructure$ ssh Administrator@192.168.1.10 -i ~\/.ssh\/id_rsa\nWindows PowerShell\nCopyright (C) 2016 Microsoft Corporation. All rights reserved.\n\nPS C:UsersAdministrator&gt; Get-Host\n\n\nName             : ConsoleHost\nVersion          : 5.1.14393.2791\nInstanceId       : 653210bd-6f58-445e-80a0-66f66666f6f6\nUI               : System.Management.Automation.Internal.Host.InternalHostUserInterface\nCurrentCulture   : en-US\nCurrentUICulture : en-US\nPrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy\nDebuggerEnabled  : True\nIsRunspacePushed : False\nRunspace         : System.Management.Automation.Runspaces.LocalRunspace\n\nPS C:UsersAdministrator&gt;<\/code><\/pre>\n<p>\nSubjective pros\/cons.<\/p>\n<p>Pros:<\/p>\n<ul>\n<li>The standard approach to connecting to servers.<br \/>\n<i>When there are a few Windows machines, it\u2019s quite inconvenient when:<br \/>\nSo, we access this one via ssh, and here it\u2019s RDP,<br \/>\nand in general, the best practice is with bastions, first an ssh tunnel, and through it RDP.<\/i><\/li>\n<li>Simplicity of configuration<br \/>\n<i>I think that's obvious.<\/i><\/li>\n<li>Speed of connection and operation with the remote machine<br \/>\n<i>There is no graphical interface, saving both server resources and the amount of data transmitted.<\/i><\/li>\n<\/ul>\n<p>\nCons:<\/p>\n<ul>\n<li>Does not completely replace RDP.<br \/>\n<i>Not everything can be done from the console, unfortunately. I mean situations where a GUI is required.<\/i><\/li>\n<\/ul>\n<p>\nMaterials used in the article:<br \/>\n<noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/PowerShell\/Win32-OpenSSH\">Link to the project itself<\/a><\/noindex><br \/>\nInstallation options are shamelessly copied from <noindex><a rel=\"nofollow\" href=\"https:\/\/docs.ansible.com\/ansible\/latest\/user_guide\/windows_setup.html#installing-win32-openssh\">Ansible docs<\/a><\/noindex>.<br \/>\n<br \/>Source: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/453676\/\">habr.com<\/a><\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u041c\u0435\u043d\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0434\u0440\u0443\u0447\u0430\u043b\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a Windows \u043c\u0430\u0448\u0438\u043d\u0430\u043c. \u041d\u0435\u0442, \u044f \u043d\u0435 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u0438\u043a \u0438 \u043d\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043a Microsoft \u0438 \u0438\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432. \u041a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0439 \u0446\u0435\u043b\u0438, \u043d\u043e \u0440\u0435\u0447\u044c \u043d\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c. \u0414\u043b\u044f \u043c\u0435\u043d\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u043b\u043e \u043c\u0443\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c \u0441 Windows, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043b\u0438\u0431\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043e\u0434\u043d\u043e \u043c\u0435\u0441\u0442\u043e (\u043f\u0440\u0438\u0432\u0435\u0442 WinRM \u0441 HTTPS) \u043b\u0438\u0431\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":26116,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-34663","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.2 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u041c\u0435\u043d\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0434\u0440\u0443\u0447\u0430\u043b\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a Windows \u043c\u0430\u0448\u0438\u043d\u0430\u043c. \u041d\u0435\u0442, \u044f \u043d\u0435 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u0438\u043a \u0438 \u043d\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043a Microsoft \u0438 \u0438\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/podklyuchenie-k-windows-po-ssh-kak-v-linux\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.2\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a Windows \u043f\u043e SSH \u043a\u0430\u043a \u0432 Linux | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u041c\u0435\u043d\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0434\u0440\u0443\u0447\u0430\u043b\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a Windows \u043c\u0430\u0448\u0438\u043d\u0430\u043c. \u041d\u0435\u0442, \u044f \u043d\u0435 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u0438\u043a \u0438 \u043d\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043a Microsoft \u0438 \u0438\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/podklyuchenie-k-windows-po-ssh-kak-v-linux\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-10-31T18:59:41+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-10-31T18:59:41+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Connecting to Windows via SSH like in Linux | ProHoster","description":"I have always been disheartened by the connection to Windows machines. No, I am neither an opponent nor a proponent of Microsoft and their products.","canonical_url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/podklyuchenie-k-windows-po-ssh-kak-v-linux","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a Windows \u043f\u043e SSH \u043a\u0430\u043a \u0432 Linux | ProHoster","og:description":"\u041c\u0435\u043d\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0434\u0440\u0443\u0447\u0430\u043b\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a Windows \u043c\u0430\u0448\u0438\u043d\u0430\u043c. \u041d\u0435\u0442, \u044f \u043d\u0435 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u0438\u043a \u0438 \u043d\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043a Microsoft \u0438 \u0438\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432.","og:url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/podklyuchenie-k-windows-po-ssh-kak-v-linux","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2019-10-31T18:59:41+00:00","article:modified_time":"2019-10-31T18:59:41+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"34663","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":"2026-01-21 20:08:19","breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-03-01 02:17:23","updated":"2026-01-21 20:08:19","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/34663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/comments?post=34663"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/34663\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media\/26116"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media?parent=34663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/categories?post=34663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/tags?post=34663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}