Guest User

Untitled

a guest
Oct 31st, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. Launch pwsh and -
  2.  
  3. $RemoteHostNameOrIP = "zerotesting5.zero.lab"
  4. $SSHUserName = "zeroadmin@zero"
  5. $LocalPortForSSHTunnel = 5998
  6. $RemoteSSHPort = 22
  7.  
  8. putty -ssh $RemoteHostNameOrIP -l $SSHUserName -L $LocalPortForSSHTunnel`:$RemoteHostNameOrIP`:$RemoteSSHPort
  9.  
  10. The above will launch a putty window where you'll have to enter your password, unless you have a key loaded in pageant. If you don't have pageant, but have a .ppk key available on your filesystem, you can do:
  11.  
  12.  
  13. putty -ssh $RemoteHostNameOrIP -l $SSHUserName -i $SSHKeyPath -L $LocalPortForSSHTunnel`:$RemoteHostNameOrIP`:$RemoteSSHPort
  14.  
  15.  
  16. Create a New PSSession -
  17.  
  18. New-PSSession -HostName localhost:5998
  19.  
  20. If you don't have an ssh key loaded into the OpenSSH-Win64 ssh-agent service (which is completely separate from putty), you'll get a password prompt:
  21.  
  22. zeroadmin@ZERO@localhost's password:
  23.  
  24. Id Name Transport ComputerName ComputerType State ConfigurationName Availability
  25. -- ---- --------- ------------ ------------ ----- ----------------- ------------
  26. 3 Runspace2 SSH localhost RemoteMachine Opened DefaultShell Available
  27.  
  28. Then test the PSSession to make sure you're on your Remote Host:
  29.  
  30. PS C:\Users\zeroadmin> Invoke-Command -Session $(Get-PSSession -Id 3) -ScriptBlock {$env:ComputerName}
  31. ZEROTESTING5
  32.  
  33. Cool!
Add Comment
Please, Sign In to add comment