Use Powershell Remoting:
Updated link:
https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/running-remote-commands?view=powershell-7
Copy pasted form an older version:
Windows PowerShell Remoting
Windows PowerShell remoting, which uses the WS-Management protocol, lets you run any Windows PowerShell command on one or many remote computers. It lets you establish persistent connections, start 1:1 interactive sessions, and run scripts on multiple computers.
To use Windows PowerShell remoting, the remote computer must be configured for remote management.
After you have configured Windows PowerShell remoting, many remoting strategies are available to you. The remainder of this document lists just a few of them.
#Start an Interactive Session
To start an interactive session with a single remote computer, use the Enter-PSSession cmdlet. For example, to start an interactive session with the Server01 remote computer, type:
Enter-PSSession Server01
The command prompt changes to display the name of the computer to which you are connected. From then on, any commands that you type at the prompt run on the remote computer and the results are displayed on the local computer.
To end the interactive session, type:
Exit-PSSession
#Run a Remote Command
To run any command on one or many remote computers, use the Invoke-Command cmdlet. For example, to run a Get-UICulture command on the Server01 and Server02 remote computers, type:
invoke-command -computername Server01, Server02 {get-UICulture}
The output is returned to your computer.
LCID Name DisplayName PSComputerName
---- ---- ----------- --------------
1033 en-US English (United States) server01.corp.fabrikam.com
1033 en-US English (United States) server02.corp.fabrikam.com
#Run a Script
To run a script on one or many remote computers, use the FilePath parameter of the Invoke-Command cmdlet. The script must be on or accessible to your local computer. The results are returned to your local computer.
For example, the following command runs the DiskCollect.ps1 script on the Server01 and Server02 remote computers.
invoke-command -computername Server01, Server02 -filepath c:\Scripts\DiskCollect.ps1
#Establish a Persistent Connection
To run a series of related commands that share data, create a session on the remote computer and then use the Invoke-Command cmdlet to run commands in the session that you create. To create a remote session, use the New-PSSession cmdlet.
For example, the following command creates a remote 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, you can run any command in them. And because the sessions are persistent, you can collect data in one command and use it in a subsequent command.
For example, the following command runs a Get-Hotfix command in the sessions in the $s variable and it saves the results in the $h variable. The $h variable is created in each of the sessions in $s, but it does not exist in the local session.
invoke-command -session $s {$h = get-hotfix}
Now you can use the data in the $h variable in subsequent commands, such as the following one. The results are displayed on the local computer.
invoke-command -session $s {$h | where {$_.installedby -ne "NTAUTHORITY\SYSTEM"} }
I think you should be able to combine this idea with this other idea and get something like this to work:
CMDS=$(cat <<CMD
read -e -p "Enter the path to the find: " FILEPATH
echo \$FILEPATH
#find \$FILEPATH -name $FILENAME
#read -p done:
CMD
)
tmux new -s finder -n remote "ssh localhost -t '$CMDS'" \; \
new-window -n local "bash -c '$CMDS'" \; \
attach \;
Bonus - both commands are running in parallel and in the same tmux
session.
Some quoting and escaping issues may remain depending upon the complexity of the commands you want to execute. Also note the read -p done
or your commands will execute, terminate and the tmux
will also terminate without you seeing the output. Perhaps that's what you intended, and the use of find
was merely for example.
Best Answer
Look into installing sshfs if you're on Linux. You can remotely connect to a machine over ssh, but it will show it as part of the file system on your local machine, so you can edit files in your local editor, and treat it as if it were a local file. You don't even have to install anything on the server side, it all just works off of ssh.
Similarly, there is win-sshfs for windows, which takes a similar approach to sshfs, but instead mounts the file system as a Windows network drive. Thanks for the recommendation Lexi R!
Another alternative would be using FTP to grab the files and put them onto your local machine, view and edit them as you'd like, then use FTP to put them back in place. You'd need a FTP server on the CentOS box, and you can use something like Filezilla to connect.