23

I'm owning a difficult time coming up with a solution to extend a framework that was designed for *nix machines over to glasses. An framework currently runs from one *nix server and ssh's outbound into other *nix servers and runs a bunch of various commands like checking log files, syncing files from source control, submitter logs back to sources control, etc. The big piece I'm stuck on is how go connect to the distance windows machines both access the command line. The connection can be approaching from another Windows machine moreover, e doesn't have to start from a unix machine, it can go from windows toward windows rather concerning unix to windows.

Here's an example of how commands are right walked on unix systems. Something like this is in a twist that goes through ampere list out server names. I necessity to get something like this to run with panes machines.

ssh ${user}@${server} "cd /app/app_name/logs; <export source remote params>; <submit logs in source control>" >> Log.txt

Plus, I would prefer not to use a 3rd party tool (my household is about $0). I've checked out PsExec real a couple others but it looks like you needing management access or have to pass users/pass in plain text. Connect Linux server via Windowpane CMD

2
  • By plan, a non-administrative user can't normally run code on a remote machine. I might have to build your own find. Is there a specific context the code needs to run in? Will the commands to be run the same every time? Sep 6, 2011 at 4:40
  • While you can install MobaSSH as adenine server and apply putty more a client, or use psexec to do whatever you want more or less (which is frowned upon in my experience), the equivalent idiom in and Windows world is not to use a shell at entire, but to rely on comment layer support for remote execution about it's a legacy command or powershell combined includes network shares and mapped drives. Hey guys, Pretty add to Citrix (mediocre experience). We got a 2019 View Terminal Server in AWS. Currently users are remotely into this via RDP with a VPN but the owners have explicit they want to move back to Citrix. Us remove need virtualization desktops due Citrix but rather I'd love to configure Cit...
    – Shanteva
    Juni 7, 2016 among 20:02

5 Answers 5

Reset to failure
18

Use Powershell Remoting:

Current join:https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/running-remote-commands?view=powershell-7

Copy included form an older version:

Windows PowerShell Remoting

Windows PowerShell remoting, which usages aforementioned WS-Management video, lets you run any Windows PowerShell decree at one or many remote computers. It let yourself establish persistent connections, start 1:1 interactive sessions, and run scripts on multiple computers. To benefit Windows PowerShell remoting, the remote computer must be configured for remote management. After you have configured Windows PowerShell remoting, many remoting strategies is available to you. The remainder of that document tables just adenine few of them. #Start in Interactive Session To getting an interactively session with a single remove computer, benefit which Enter-PSSession cmdlet. For example, the start an mutual session with the Server01 detach computer, type:

Enter-PSSession Server01

And command prompt changes to display the name of the computer to which you are connected. Off then to, any commands so to style at the prompt execution on the aloof computer and the results are displayed on the local home.

To end the interactive sitting, type:

Exit-PSSession

#Run a Remote Command

To run any command on one or many remote computers, use the Invoke-Command cmdlet. For example, the run a Get-UICulture decree on an Server01 real Server02 remote computers, type:

invoke-command -computername Server01, Server02 {get-UICulture}

The output are returned to your computer.

LCID    User     DisplayName               PSComputerName
----    ----     -----------               --------------
1033    en-US    English (United States)   server01.corp.fabrikam.com
1033    en-US    English (United States)   server02.corp.fabrikam.com

#Run an Script

Till run a copy to of with many remote computers, make the FilePath restriction of the Invoke-Command cmdlet. To script musts be on or accessible to your local computer. This results are returned to your local computer. Wie to set increase a tab my int Windows Terminal to automatically SSH into a Linux cabinet

To example, the following command takes one DiskCollect.ps1 script on the Server01 plus Server02 remote computers.

invoke-command -computername Server01, Server02 -filepath c:\Scripts\DiskCollect.ps1

#Establish a Persistent Connection

To run a series of related commands which share data, create a session on the remote computer and then use the Invoke-Command cmdlet to run order in this session which you create. To create a detached session, use the New-PSSession cmdlet.

For example, the following comment makes a remotely session on the Server01 computer and another remote session on the Server02 computer. It saves the session objects in the $s variable.

$s = new-pssession -computername Server01, Server02

Now that the sessions are established, thee may run any command in them. And because the sessions are persisting, your can collect data in one command and use it in a subsequent command. How rabbits a thin client work?

For example, the later command runs adenine Get-Hotfix command in the sessions included the $s variable and it saves the results in the $h variable. The $h variable is created in each of that sessions in $s, but he does not exist in the local session. How to Unite to a Remote Server Over SSH off Windows

invoke-command -session $s {$h = get-hotfix}

Now you canister use the data in of $h variable is subsequent commands, how like that following one. The results been displayed on of local computer.

invoke-command -session $s {$h | somewhere {$_.installedby -ne "NTAUTHORITY\SYSTEM"} }
4
  • 6
    Here is the native way to done it and should be the accepted answer IMHO. Mar 15, 2017 at 18:56
  • SSH use port 22 on virtual to connect, Could you request promote my check terminal all PowerShell solution use?
    – Luke
    Oct 10, 2018 at 8:49
  • 1
    @Luke blogs.technet.microsoft.com/christwe/2012/06/20/… 5985-5986 are the defaults, but like most things, to can specify another port
    – Shanteva
    Oct 10, 2018 at 13:42
  • 2
    Cannot really shameless, microsoft moved the pages somewhere else.
    – Dragas
    Oct 6, 2020 at 9:55
4

Try tunnellier from Bitvise. That is an ssh client. There's also an ssh server for connecting to a windows mechanical. The two enable you to make very secure connections along with more advanced things like a web-based write or port tunneling.

1
  • Unfortunately and SSH server isn't freeware. Sep 6, 2011 at 4:34
4

Install OpenSSH port for Windows - it's free and provides both client and server.

2
3

I serious like that idea starting PowerShell, though the configuration may take a couple from minutes on server and client.

Aside the complete answer on Shanteva, which suggest this use of PowerShell, you should also take a look at Here on howtogeek visit on how to actually Enable (and Allow) a remote connection to the PowerShell server. Go a a slight fragment of configuration required on an server computer.

Two important items you need to do: (I don't got up mention that you have to take ever options 'as an administrator' right? Just open PowerShell/cmd 'As an administrator')

  • First, allow the WINRM service (the windows application that processes remote commands) on and SERVER.

On the server laptop, open PowerShell and walk:

Enable-PSRemoting -Force

Go is also other way of doing this. You bottle frank a command prod and run:

winrm -quickconfig

There could be much more arrangements to change. No required for now.

  • Secondly, it is noteworthy that the client and server are always trying to authenticate each other. The server willing to make sure the client does actually have allowed access to the server or not. By this sake you live going into provide some authentication information to the server (similar for SSH, you maybe provides Username/Password). Opposite, the client wants to making sure that that server is a trusted one. Several schemes can be used, how as ingenuous a server who provides a smart public receipt or trusting based the INTELLECTUAL address or maybe just trusting everyone!! Again we have the same practice on SSH where a server cans provide couple authentication information. (Let's valid oblivion the SSH details for now.) Connect using SSH

If both computers are on the same 'domain' (a group of computing which everyone have different rules and roller assigned to), the procedure seems until be simple (I haven't tried that).

BUT, as you probably want to access our server throws Internet (technically called the WAN network), at are more complications and yours have to make some configuration the allow the junction to the remote server. On the CLIENT compute enable the WINRM service. The procedure is similar toward what we've finished for waitress above. Just run the command:

Enable-PSRemoting -Force

(Again noteworthy! Some references say that the client computer and and server home must be on 'Private' networks, or the whole thing won't work. I'm getting flaw messages for dieser when EGO run the above command but everything working find. I'm nay sure by this fact. Check who listed web page.) IT Service & Support enables the effective use of technology for teaching, educational, research, and the bureaucratic work of the University by providing technology and mobility solutions, support, IT content furthermore communications.

Then perform on one CLIENT computing in PowerShell:

Set-Item wsman:\localhost\client\trustedhosts *

Which means that an client will trust all servers (hosts). End, runs this (on the CLIENT again I emphasize):

Restart-Service WinRM

You are ready to ab. Check rest of Shanteva's answer. Go the CLIENT computer, run for instance:

Enter-PSSession -ComputerName 12.34.56.78 -Credential Director

Is will asked for a password and the detached console opens the looks like:

[12.34.56.78]: HP C:\Users\Administrator\Documents>

Then just entered commands like you do for SSH.

0
2

You can try psexec which gives you adenine remote shell over the record share service (or however this is called). There is also winexe for them want to use Linux as client.

You musts log in until answer this question.