'Allow SSH from PowerShell without Administrator privileges
I mean to get a terminal in an Ubuntu 20.04LTS server via ssh under PS 5.1 in Win 10. I know I can work with native support for OpenSSH, and I have already done it before.
Now I want to do it without having admin rights, to minimize "tainting" my system. For reasons described below (1), I think I cannot work with native OpenSSH.
For reasons described below (2), I think it is possible. For instance, I can already start a session and issue remote commands ref, see below (3). But I couldn't start a terminal.
Is there a way to accomplish what I mean? How?
(1) Why, for my purposes, I cannot work with native OpenSSH?
For instance, the first two commands in the PS-way of enabling OpenSSH already require admin (my PS is in Spanish):
> Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
Get-WindowsCapability : La operación solicitada requiere elevación.
> Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Add-WindowsCapability : La operación solicitada requiere elevación.
(2) Why I think it might be possible to get an ssh terminal without admin rights in PS?
Because I can already perform several similarly demanding actions as a regular user without admin rights, outside PS:
1.1. I can ssh from
Msys2portable1.2. I can connect from
putty(portable)1.3. I can transfer via
WinSCPportableItem (3) below.
(3) How to start an ssh session and issue remote commands from PS
Install Posh-SSH for the current user only.
Then
> New-SSHSession -Host xxx.xxx.0.xxx -Credential (Get-Credential)
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
Server SSH Fingerprint
Do you want to trust the fingerprint xx:xx:...
[] Y [] N [?] Ayuda (el valor predeterminado es "N"): y
SessionId Host Connected
--------- ---- ---------
0 xxx.xxx.0.xxx True
> Get-SSHSession
SessionId Host Connected
--------- ---- ---------
0 xxx.xxx.0.xxx True
> Invoke-SSHCommand -Index 0 -Command "pwd"
Host : xxx.xxx.0.xxx
Output : {/home/user1}
ExitStatus : 0
Solution 1:[1]
Windows 10 has SSH built in since v1809. An OpenSSH-Client is already installed, you can directly use it by calling ssh. Try Get-Command ssh. It should return C:\WINDOWS\System32\OpenSSH\ssh.exe. You can connect to anything that supports SSH without administrative privileges "out of the box":
ssh -l <username> <DNS-Name/IP>
There is also an OpenSSH-Server available, but has to be enabled as a feature first. You probably need administrative privileges to enable that.
Solution 2:[2]
The latest versions of Windows 10 (and 11) have the ssh.exe built-in. It does not need to be installed. If you do not have it, you either do not have up-to-date version of Windows 10, or the OpenSSH component was somehow explicitly removed/forbidden.
Anyway, you can download ssh.exe manually from Win32-OpenSSH project. You do not need Administrator permissions for that. It does not need any installation.
But on the other hand, if you are not supposed to install software, why are you trying to bypass those restrictions, if you already have PuTTY? Use PuTTY, not ssh. If you need a console tool for automation, you can use PuTTY plink.exe. It's a console equivalent of PuTTY. And for automation purposes, it's identical to OpenSSH ssh (it does not have all the interactive features of ssh – for interactive purposes, use PuTTY).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | stackprotector |
| Solution 2 |
