{"id":499,"date":"2024-08-21T00:49:05","date_gmt":"2024-08-20T21:49:05","guid":{"rendered":"https:\/\/itgen.itbumper.com\/?page_id=499"},"modified":"2024-11-08T12:20:24","modified_gmt":"2024-11-08T09:20:24","slug":"connecting-to-windows-via-ssh-as-in-linux","status":"publish","type":"page","link":"https:\/\/itgen.itbumper.com\/?page_id=499","title":{"rendered":"0011_Connecting to Windows via SSH as in Linux"},"content":{"rendered":"<p style=\"text-align: justify;\" data-tadv-p=\"keep\">First, you download <a href=\"http:\/\/Download https:\/\/github.com\/PowerShell\/Win32-OpenSSH\/releases\" data-wplink-url-error=\"true\">OpenSSH<\/a>; choose the correct version, 32 or 64-bit.<\/p>\n<p style=\"text-align: justify;\" data-tadv-p=\"keep\">Unpack the archive to <em>C:\\Program Files<\/em><i>\\OpenSSH\u00a0<\/i>for 64-bit, to <em>C:\\Program Files (x86)\\OpenSSH<\/em> for 32-bit<\/p>\n<p style=\"text-align: justify;\" data-tadv-p=\"keep\">In my case, I use the 64-bit version.<\/p>\n<p style=\"text-align: justify;\" data-tadv-p=\"keep\"><span style=\"color: #ff0000;\"><strong>!<\/strong><\/span> Be sure only the SYSTEM and Admins group can access this folder.<\/p>\n<p style=\"text-align: justify;\" data-tadv-p=\"keep\">From the administrative side, we run the install-sshd.ps1 script is located in this program directory and will install the application as a service. I run PowerShell, and here are my actions:<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\ncd &quot;C:\\Program Files\\OpenSSH&quot;\npowershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1\npowershell.exe -ExecutionPolicy Bypass -File FixHostFilePermissions.ps1\npowershell.exe -ExecutionPolicy Bypass -File FixUserFilePermissions.ps1\n<\/pre><\/div>\n\n<p>Allow inbound TCP port 22<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n# for Windows 2012 and above\nNew-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22\n\n# for others try to use\nnetsh advfirewall firewall add rule name=sshd dir=in action=allow protocol=TCP localport=22\n<\/pre><\/div>\n\n<p>Start service<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nnet start sshd\n<\/pre><\/div>\n\n<p><span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"0:3\">At<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"4:7\">startup<\/span>, the <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"46:4\">host<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"51:5\">keys<\/span> will <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"12:5\">be<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"18:13\">automatically<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"32:13\">generated<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"57:1\">(<\/span><span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"58:4\">if<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"63:11\">missing<\/span><span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"74:1\">)<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"76:1\">in<\/span> <i>%programdata%\\ssh<\/i><\/p>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"342\" height=\"348\" src=\"https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2024\/08\/openssh02.png\" alt=\"\" class=\"wp-image-502\" srcset=\"https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2024\/08\/openssh02.png 342w, https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2024\/08\/openssh02-295x300.png 295w\" sizes=\"(max-width: 342px) 85vw, 342px\" \/><\/figure><\/div>\n\n<p><span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"39:2\">We<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"42:5\">can<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"48:8\">enable<\/span> the&nbsp;<span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"0:10\">autorun<\/span> of the <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"11:7\">service<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"19:3\">at<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"31:7\">system<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"23:7\">startup<\/span> with the <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"57:8\">command<\/span>:<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nSet-Service sshd -StartupType Automatic\n<\/pre><\/div>\n\n<p>You <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"0:5\">can<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"6:7\">change<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"33:2\">the<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"36:9\">default<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"14:9\">command<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"24:8\">shell<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"46:1\">(<\/span><span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"47:5\">after<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"53:9\">installation<\/span><span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"62:1\">,<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"64:2\">the<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"67:9\">default<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"77:1\">is<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"79:3\">cmd<\/span><span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"82:1\">)<\/span>: The <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"106:10\">absolute<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"117:4\">path<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"85:10\">must<\/span> be <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"96:9\">specified<\/span><span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"121:1\">.<\/span><\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nNew-ItemProperty -Path &quot;HKLM:\\SOFTWARE\\OpenSSH&quot; -Name DefaultShell -Value &quot;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe&quot; -PropertyType String -Force\n<\/pre><\/div>\n\n<p>I <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"16:4\">will<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"21:12\">use<\/span> a <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"34:4\">key<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"0:3\">to<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"4:11\">connect and <\/span><span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"59:7\">disable<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"40:9\">password<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"50:6\">access<\/span><span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"66:1\">.<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"68:3\">To<\/span> do <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"72:5\">this<\/span>, I will <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"78:12\">edit<\/span> the <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"91:4\">file <\/span><i>C:\\ProgramData\\ssh\\sshd_config<\/i><\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nPasswordAuthentication no\nPubkeyAuthentication yes\n<\/pre><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"678\" height=\"476\" src=\"https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2024\/08\/openssh03.png\" alt=\"\" class=\"wp-image-503\" style=\"width:630px;height:auto\" srcset=\"https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2024\/08\/openssh03.png 678w, https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2024\/08\/openssh03-300x211.png 300w\" sizes=\"(max-width: 678px) 85vw, 678px\" \/><\/figure><\/div>\n\n<p style=\"text-align: justify;\" data-tadv-p=\"keep\">Create the <em>.ssh<\/em> directory in the user folder, and the <em>authorized_keys<\/em> file is in it. We record the public keys there. To create a folder <em>.ssh<\/em>, use the command <em>mkdir .ssh<\/em><\/p>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"478\" height=\"188\" src=\"https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2024\/08\/openssh04.png\" alt=\"\" class=\"wp-image-504\" srcset=\"https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2024\/08\/openssh04.png 478w, https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2024\/08\/openssh04-300x118.png 300w\" sizes=\"(max-width: 478px) 85vw, 478px\" \/><\/figure><\/div>\n\n<p style=\"text-align: justify;\" data-tadv-p=\"keep\"><span style=\"color: #ff0000;\"><strong>!<\/strong><\/span> It is critical that <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"49:6\">only<\/span> the <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"56:12\">user<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"70:1\">in<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"72:4\">whose<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"77:10\">directory<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"88:5\">the<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"94:4\">file<\/span> is located <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"36:6\">should<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"43:5\">have<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"16:6\">write<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"7:5\">rights<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"13:2:23:1\">to<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"25:4\">this<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"30:4\">file<\/span><span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"34:1\">,<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"99:3\">or<\/span> you <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"103:5\">can<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"109:9\">disable<\/span> the <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"128:4\">rights<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"119:8\">check<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"133:1\">in<\/span> the <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"135:16\">configuration<\/span> <span class=\"EzKURWReUAB5oZgtQNkl\" data-src-align=\"152:5\">file<\/span>&nbsp;<i>C:\\ProgramData\\ssh\\sshd_config<\/i>:<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nStrictModes no\n<\/pre><\/div>\n\n<p style=\"text-align: justify;\" data-tadv-p=\"keep\">After any changes are made to the configuration file, it is necessary to restart the sshd service:<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnet stop sshd\nnet start sshd\n<\/pre><\/div>\n\n<p style=\"text-align: justify;\" data-tadv-p=\"keep\">Add your public key in a file&nbsp; <em>authorized_keys<\/em><\/p>\n<p style=\"text-align: justify;\" data-tadv-p=\"keep\">Try to connect to the server. If you can&#8217;t connect, use ssh -v username@yourserver on the client&#8217;s side, and start the ssh server in debug mode sshd -d. If you got in trouble with a connection using a public key, please visit this <a href=\"https:\/\/superuser.com\/questions\/1445976\/windows-ssh-server-refuses-key-based-authentication-from-client\">page.<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>First, you download OpenSSH; choose the correct version, 32 or 64-bit. Unpack the archive to C:\\Program Files\\OpenSSH\u00a0for 64-bit, to C:\\Program Files (x86)\\OpenSSH for 32-bit In my case, I use the 64-bit version. ! Be sure only the SYSTEM and Admins group can access this folder. From the administrative side, we run the install-sshd.ps1 script is &hellip; <a href=\"https:\/\/itgen.itbumper.com\/?page_id=499\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;0011_Connecting to Windows via SSH as in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/499"}],"collection":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=499"}],"version-history":[{"count":10,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/499\/revisions"}],"predecessor-version":[{"id":681,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/499\/revisions\/681"}],"wp:attachment":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}