{"id":80905,"date":"2016-11-25T00:01:52","date_gmt":"2016-11-25T08:01:52","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=80905"},"modified":"2019-02-18T09:10:20","modified_gmt":"2019-02-18T16:10:20","slug":"open-source-powershell-part-4","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/open-source-powershell-part-4\/","title":{"rendered":"Open Source PowerShell \u2013 Part 4"},"content":{"rendered":"<p><strong>Summary<\/strong>: Install and Configure SSH for Open Source PowerShell remoting.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/> With PowerShell, up to this point, one thing that I love is the ability to connect various systems in my environment and run cmdlets on them remotely.\u00a0 Can we do this with Open Source PowerShell?<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>\u00a0Honorary Scripting Guy, Sean Kearney, is here today to go over how to get Open Source PowerShell set up to do remoting.\u00a0 Because this, my friends, this is the <u>big<\/u> game changer.<\/p>\n<p>When Linux admins presently need to work with a Windows Server, they need to play with a few options:<\/p>\n<ul>\n<li>Remote desktop (RDP) to the server<\/li>\n<li>Install Secure Shell (SSH) and run an SSH session to the Windows\u00a0computer<\/li>\n<li>Install a third-party solution such as VNC on the Windows\u00a0computer<\/li>\n<\/ul>\n<p>A\u00a0Windows admin could typically just download a utility like Putty and hop off to work.\u00a0 However, both of these solutions are limited\u00a0because they lack a key piece in automation.<\/p>\n<p>When you run a script against either system, you can only visually see the status code that the application produced or perhaps lines of red on the screen.<\/p>\n<p>There is no built-in way for a Linux admin to easily run a Windows PowerShell script and have the value passed back to Bash to allow them to action up it. It is a similar issue for Windows admins when they run Bash scripts remotely. The Windows computer\u00a0does not have a simple way to see that the script produced an error code of say, -3.<\/p>\n<p>With Open Source, PowerShell remoting was one of the big pieces to change this scenario and level\u00a0the playing field. The requirements on both end points (Linux\/macOS and Windows) are pretty simple.<\/p>\n<ul>\n<li>SSH client and server<\/li>\n<li>Open Source PowerShell<\/li>\n<li>Appropriate firewall ports opened<\/li>\n<\/ul>\n<p>In Linux and in Windows, just install Open Source PowerShell according to the\u00a0<a target=\"_blank\" href=\"https:\/\/github.com\/powershell\/powershell\">instructions on Github under \u2018Get PowerShell\u2019<\/a>.<\/p>\n<p>On the Linux and macOS side, you\u2019ll need to make sure you are running <code>openssh-client<\/code> and <code>openssh-server<\/code>. For the Windows side, you need to <a target=\"_blank\" href=\"https:\/\/github.com\/PowerShell\/Win32-OpenSSH\">download and install Win32 Open SSH<\/a>, which is a port of openssh for Windows.<\/p>\n<p>After it&#8217;s\u00a0installed, you need to configure the endpoints. On Windows, you\u2019ll need to open up and edit the sshd_config file in the C:\\Program Files\\OpenSSH folder and make the following changes.<\/p>\n<p>Find the following lines in the file, and edit them to reflect the following values. (Remove the # preceding the value if needed,)<\/p>\n<p style=\"padding-left: 30px\"><code>PasswordAuthentication yes<\/code><\/p>\n<p style=\"padding-left: 30px\"><code>RSAAuthentication yes<\/code><\/p>\n<p style=\"padding-left: 30px\"><code>PubkeyAuthentication yes<\/code><\/p>\n<p>You\u2019ll also need to find the following line.<\/p>\n<p style=\"padding-left: 30px\"><code>Subsystem\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sftp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 C:\/Program Files\/OpenSSH\/sftp-server.exe<\/code><\/p>\n<p>Add this line directly below it.<\/p>\n<p style=\"padding-left: 30px\"><code>Subsystem\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 powershell C:\/Program Files\/PowerShell\/6.0.0.10\/powershell.exe -sshs -NoLogo -NoProfile<\/code><\/p>\n<p>Of course, you\u2019ll need to make sure this path matches the install location for your release of Open Source PowerShell. \u00a0After that&#8217;s done, restart the sshd service in Windows. In PowerShell, you can simply execute.<\/p>\n<p style=\"padding-left: 30px\"><code>Restart-Service sshd<\/code><\/p>\n<p>In Linux and macOS, you\u2019ll make similar edits to the local sshd_config file.<\/p>\n<p style=\"padding-left: 30px\"><code>PasswordAuthentication yes<\/code><\/p>\n<p style=\"padding-left: 30px\"><code>RSAAuthentication yes<\/code><\/p>\n<p style=\"padding-left: 30px\"><code>PubkeyAuthentication yes<\/code><\/p>\n<p>And instead of this value:<\/p>\n<p style=\"padding-left: 30px\"><code>Subsystem\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 powershell C:\/Program Files\/PowerShell\/6.0.0.10\/powershell.exe -sshs -NoLogo -NoProfile<\/code><\/p>\n<p>In Linux and macOS, you won\u2019t need to supply the path to PowerShell. (Presently, you have two versions on Windows, and we need to explicitly target the Open Source version,) The value will look like this.<\/p>\n<p>Add this line directly below it.<\/p>\n<p style=\"padding-left: 30px\"><code>Subsystem\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 powershell powershell -sshs -NoLogo -NoProfile<\/code><\/p>\n<p style=\"padding-left: 30px\"><code>Restart that Daemon in Linux using the following command<\/code><\/p>\n<p style=\"padding-left: 30px\"><code>sudo service ssh restart<\/code><\/p>\n<p>When you&#8217;re\u00a0done, you should be able to connect to Windows from Linux by using any standard client and vice versa.<\/p>\n<p>So, you\u2019ve got SSH running on both endpoints. Now what?<\/p>\n<p>Next Friday, we show you the coolest thing ever. Running PowerShell remoting <span style=\"text-decoration: underline\">over<\/span>\u00a0SSH and actively running and receiving the status of scripts from either side!<\/p>\n<p>I invite you to follow the Scripting Guys on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to them at <a target=\"_blank\" href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow.<\/p>\n<p>Until then, always remember that with Great PowerShell comes Great Responsibility.<\/p>\n<p><strong>Sean Kearney\n<\/strong>Honorary Scripting Guy\nCloud and Datacenter Management MVP<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Install and Configure SSH for Open Source PowerShell remoting. With PowerShell, up to this point, one thing that I love is the ability to connect various systems in my environment and run cmdlets on them remotely.\u00a0 Can we do this with Open Source PowerShell? \u00a0Honorary Scripting Guy, Sean Kearney, is here today to go [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[568,641],"tags":[56,154,45],"class_list":["post-80905","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","category-windows-powershell","tag-guest-blogger","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Install and Configure SSH for Open Source PowerShell remoting. With PowerShell, up to this point, one thing that I love is the ability to connect various systems in my environment and run cmdlets on them remotely.\u00a0 Can we do this with Open Source PowerShell? \u00a0Honorary Scripting Guy, Sean Kearney, is here today to go [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/80905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=80905"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/80905\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=80905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=80905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=80905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}