When attempting to remotely log into a Windows machine from Ubuntu using PowerShell, you might encounter the following error:
The SSH client session has ended with error message: The SSH transport process has abruptly terminated causing this remote session to break.
Ensure installed ssh service:
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
To resolve this issue, follow these steps:
- Edit SSH Configuration: Navigate to
C:\ProgramData\ssh\sshd_config
on your Windows machine.
Locate the line# override default of no subsystems.
Directly below this line, add:Subsystem powershell "C:\Progra~1\PowerShell\7\pwsh.exe" -sshs -NoLogo -NoProfile - Restart SSH Service: Use the command line to execute:
Restart-Service sshd - Establish SSH Session: From your Ubuntu machine, execute the following command in PowerShell:
Enter-PSSession -HostName 192.168.1.5 -UserName yourUserName -SSHTransport
With these adjustments, you should be able to successfully log in to your Windows machine from Ubuntu using PowerShell over SSH.
to run as Administrator: eg:
Start-Process -FilePath "powershell" -ArgumentList "-Command dir > D:\output.txt" -Verb RunAs
reference: