{"id":1453,"date":"2022-01-03T20:52:49","date_gmt":"2022-01-03T20:52:49","guid":{"rendered":"https:\/\/howden.net.au\/thowden\/?p=1453"},"modified":"2022-01-18T23:17:33","modified_gmt":"2022-01-18T23:17:33","slug":"change-the-port-for-openssh-on-windows-2019","status":"publish","type":"post","link":"https:\/\/howden.net.au\/thowden\/2022\/01\/change-the-port-for-openssh-on-windows-2019\/","title":{"rendered":"Change the Port for OpenSSH on Windows 2019"},"content":{"rendered":"\n<p>Hopefully a quick How-To Change the Port for OpenSSH on Windows 2019.<\/p>\n\n\n\n<p>Ok, so we have OpenSSH installed on Windows Server 2019, but it is using the default SSH Port 22. Which is ok but if you are opening this up to the internet then maybe not so much as the kiddie-scripts will hammer this port with brute-force attacks. A better option is to change to a non-default high port number. Yes, arguments will continue over doing this or not, good, better, best practice, etc., but lets just focus on the technical aspect and save the flame-wars for another millenia. <\/p>\n\n\n\n<p>First up, we need to modify the sshd server setting which is done by editing the sshd_config file. Which depending on where you look may appear to be found in c:\\windows\\system32\\openssh\\ but that is <em>not the file you are looking for<\/em>. You need to look for and edit c:\\%programdata%\\ssh\\sshd_config (thanks to <a rel=\"noreferrer noopener\" href=\"https:\/\/ebinissac.me\/2019\/02\/25\/how-to-change-the-openssh-server-port-in-windows\/\" target=\"_blank\">Ebin Issac<\/a> for that clue). The file also needs Admin permissions to save the changes, so if you are using Notepad.exe to do the edit, open Notepad as Administrator and then open the file. Right-click the file and Open with Notepad will not allow you to save the changes. <\/p>\n\n\n\n<p>Edit the file to change the port:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">#Port 22    &lt;-- in this line remove the # and change 22 to your desired port number<\/pre>\n\n\n\n<p>Now save the file and stop \/ start the sshd service. <\/p>\n\n\n\n<p>Next use netstat to check if the new port is listening<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">netstat -na | find your-port-number<\/pre>\n\n\n\n<p>Now, before you leap into the command, if you are using PowerShell (PoSh) then the find command will probably give you a &#8220;FIND: Parameter format not correct&#8221;  as the &#8216;your-port-number&#8217; is a string and will need to be enclosed in quotes, but not just any quotes. For whatever bizarre reason, we need to escape the quote marks for PoSh. <\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">netstat -na | find \"\"\"your-port-number\"\"\"    &lt;---  yes, triple quotation marks to escape the escaped!<\/pre>\n\n\n\n<p>or you can also using the back-tick ` mark like this <\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">netstat -na | find `\"your-port-number`\"   &lt;--- the back-ticks escape the quote mark, so this is a bit shorter<\/pre>\n\n\n\n<p>So you should have a response something like this:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">PS C:\\windows\\system32> netstat -na | find `\"12345`\"\n  TCP    0.0.0.0:12345          0.0.0.0:0              LISTENING\n  TCP    [::]:12345             [::]:0                 LISTENING<\/pre>\n\n\n\n<p>Noting that the port number used of 12345 is not recommended, the real port number has been changed. <\/p>\n\n\n\n<p>Then modify Windows firewall entry (assumes you configured the firewall rule using Microsoft instruction set) with PowerShell using your port number (not 12345)<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">Set-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -LocalPort 12345<\/pre>\n\n\n\n<p>and your hardware firewall if needed. <\/p>\n\n\n\n<p>Reference for the PoSh Find command was <a rel=\"noreferrer noopener\" href=\"https:\/\/superuser.com\/questions\/983105\/find-parameter-format-not-correct-and-findstr-write-error-with-pipes\" target=\"_blank\">https:\/\/superuser.com\/questions\/983105\/find-parameter-format-not-correct-and-findstr-write-error-with-pipes<\/a>.<\/p>\n\n\n\n<p>Reference for the firewall changes via PoSh <a href=\"http:\/\/woshub.com\/manage-windows-firewall-powershell\/#h2_2\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/woshub.com\/manage-windows-firewall-powershell\/#h2_2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hopefully a quick How-To Change the Port for OpenSSH on Windows 2019. Ok, so we have OpenSSH installed on Windows Server 2019, but it is using the default SSH Port 22. Which is ok but if you are opening this up to the internet then maybe not so much as the kiddie-scripts will hammer this [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[127,22],"tags":[],"class_list":["post-1453","post","type-post","status-publish","format-standard","hentry","category-openssh","category-windows-servers"],"_links":{"self":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts\/1453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/comments?post=1453"}],"version-history":[{"count":3,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts\/1453\/revisions"}],"predecessor-version":[{"id":1456,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts\/1453\/revisions\/1456"}],"wp:attachment":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/media?parent=1453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/categories?post=1453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/tags?post=1453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}