# PowerShell Remoting via SSH
https://docs.microsoft.com/en-us/powershell/scripting/core-powershell/ssh-remoting-in-powershell-core?view=powershell-6
# Install Latest PowerShell Core (it has SSH Connection) from here - Stable MSI in table:
https://github.com/PowerShell/PowerShell/
#Install Win32 OpenSSH
See HERE: https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH
# Download latest release from here:
https://github.com/PowerShell/Win32-OpenSSH/releases
# Extract contents of the latest build to C:\Program Files\OpenSSH
# In Admin console, run install:
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
# Adjust Firewall for Port 22
Server:
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Desktop
netsh advfirewall firewall add rule name=sshd dir=in action=allow protocol=TCP localport=22
# Auto Start
Set-Service sshd -StartupType Automatic
Set-Service ssh-agent -StartupType Automatic
# Note: To Uninstall OpenSSH, go to install directory and do this (as Admin):
powershell.exe -ExecutionPolicy Bypass -File uninstall-sshd.ps1
# Modify sshd_config_default file within C:\Program Files\OpenSSH\ directory
# and name it sshd_config:
Un-Comment:
PasswordAuthentication yes
PubkeyAuthentication yes
Also, Add/Un-Comment:
RSAAuthentication yes
Add:
Subsystem powershell c:/program files/powershell/6.0.2/pwsh.exe -sshs -NoLogo -NoProfile
# Restart the Service
Restart-Service sshd
# Add OpenSSH locationt to Path environment variable:
C:\Program Files\OpenSSH\
#############################################
#############################################
The following is required to enable cross-platform Powershell Remoting
Reference: https://blogs.technet.microsoft.com/heyscriptingguy/2017/12/29/cross-platform-powershell-remoting-in-action/
On Windows, Generate an RSA Key
PS C:\Users\USER> ssh-keygen -t rsa -f optiplexrsakey
The keys will be generated in the home directory (see: $HOME), eg. c:\users\USER
Now, place the generated .pub file onto the linux box
Then, add the public key to authorized keys:
osmc@osmc:~$ mkdir -p .ssh
osmc@osmc:~$ chmod 700 .ssh
osmc@osmc:~$ cat ./rsakey.pub >> .ssh/authorized_keys
osmc@osmc:~$ chmod 640 .ssh/authorized_keys
osmc@osmc:~$ sudo service sshd restart
Now you can test the connection:
PS > Invoke-Command -ScriptBlock {"Hello from $(hostname)"} -UserName osmc -HostName 192.168.1.2 -KeyFilePath C:\Users\USER\rsakey
# The following prompt will display the first time:
The authenticity of host '192.168.1.2 (192.168.1.2)' can't be established.
ECDSA key fingerprint is SHA256:ABcdeF+gHijklmnoPqrS/TuvWxyz12/345+67890ABc.
Are you sure you want to continue connecting (yes/no)?
Warning: Permanently added '192.168.1.2' (ECDSA) to the list of known hosts.
Hello from osmc
PS > Invoke-Command -ScriptBlock {(Get-ChildItem /media/DRIVE -File).Name} -UserName osmc -HostName 192.168.1.2 -KeyFilePath C:\Users\USER\rsakey
MOVIE1 (2018).mkv
MOVIE2 (2018).mkv
MOVIE3 (2018).mkv