SSH from Linux to Windows does not execute commands in windows environment(only as background process)

0

I am somewhat out of my dept here, so please go easy on me. I installed Openssh on both linux vm and Windows vm in vmware. As far as I can tell this implements some form of cygwin on windows. I can ssh to the user folder:

C:\Program Files\OpenSSH\home\ATV>

, like this:

ssh -p22 -t ATV@DESKTOP-CGHF9HU bash

or like this:

ssh -p22 -t ATV@DESKTOP-CGHF9HU cmd OpenExcelFile.vbs

or similar with cmd or sh. I can cd and DIR to my hearts content, and I can run .exe's, scripts you name it. It is just that they all start as background processes.

I want to be able to trigger ACTUAL execution of applications in the foreground.

The basics of it, I can access the command line and my windows os system through my linux terminal. I can dir file system and cd everything there. But I cannot run anything as foreground application, only as background processes, and I would like to trigger the actual opening of Microsoft Excel in the windows vm gui?

EDIT: The problem is the display.... I can start Microsoft Excel, and see it running in background processes. So I guess the question would be how to be able to :

  • Either start an application in the foreground over ssh.
  • Or trigger a script that would open Excel in a "window".

Right now I am transferring the "file" via scp from python

os.system('scp CalculatedOutput/Opera.csv ATV@DESKTOP-CM5F9HU:')
os.system('ssh -t ATV@DESKTOP-CGHF9HU  RunIf.vbs')

, trying to open the script through ssh.

I also managed to find version 1.1 of winexe, but there seem to be a lot of problems with this client. I have scoured the net, but no combinations of the syntax seems to work:

os.system('./winexe --user=\DESKTOP-CGHF9HU/ATV%Mypassword   //windows.domain.local --interactive=1 --uninstall --system  OpenExcelFile.vbs')

My guess would be that some people know how to do(hack) this. Why you would want to ? Unless you are a unix purist I would think it obvious...

I didn't have the opportunity to give up on this, so I continued digging. As mentioned in the comments below there are indeed access restrictions, and I guess microsoft wouldn't want to allow access to their os. Nevertheless, seeing as your other windows settings allow sharing and your syntax is correct:

./winexe -U ATV%password //DESKTOP-CGHF9HU 'cmd.exe'

, you can edit your registry as per https://tommynation.com/enable-remote-access-administrative-shares-windows-10/ , and the winexe1.1 will indeed allow you access. Now I know this isn't safe, but all my vm's are physically under my control so I DO NOT CARE.

Moving on the problem still persists though, as my code above actually gives you access to the windows command line, but still opens applications in the background. I can not bring them to the foreground( as in -fg), and the purpose is defeated. Question remains, how do I get them to display ? I can do the same thing with openssh and cygwin so what is then the purpose of the winexe application ?

Edit2: Well, I'm not going to call it quits here, but The best way for me to do this at the moment, is transferring the file in question, then running the "if(file exists)" script at the same time over ssh(From python):

os.system('scp CalculatedOutput/Opera.csv ATV@DESKTOP-CGHF9HU:')
os.system('ssh -p22 -t ATV@DESKTOP-CGHF9HU "cscript RunIf.vbs"')

The vbscript for automating Excel is automatically run in the background with Excel, and I guess the fact that I manually have to open Excel for visualization is something I will have to live with for the time being. That WAS my original question though, so I will still leave this unanswered.

PushT

Posted 2017-11-20T02:24:27.860

Reputation: 21

There are other details that come in to play when you are trying to remotely execute code. There are Windows tools for this like powershell. But, when you connect remotely to a system, you need to consider what user you are connecting as, if you are running with elevated permissions, and if you are interacting with the console or not. For instance, you might be connecting to the remote computer in the "SYSTEM" context in which case no visible windows will be present and some applications might not be able to execute that way. My preferred tool for this is psexec. – Appleoddity – 2017-11-20T03:18:07.453

That's poweshell exec? Thank you, I am one step further. How would you target PowerShell from linux. And there would have to be some path variable added on windows I presume ? – PushT – 2017-11-20T03:25:49.600

Sorry, my post was a bit confusing and didn't take in to consideration you were using Linux to connect to Windows. Powershell and psexec are Windows tools for remote administration. They won't be available on Linux. The rest of my comments still hold true. I had a very hard time finding any details about SSH on Windows in regards to your question. I apologize. You may be interested in Microsoft's native SSH support: https://www.ctrl.blog/entry/how-to-win10-ssh-service

– Appleoddity – 2017-11-20T03:43:25.717

Looks like there is a Linux equivalent of PSEXEC called Winexe It may work better for you also. You'll see the options for an interactive session, or system session.

– Appleoddity – 2017-11-20T03:45:43.557

I have seen this winexe application, let's just hope I can build it. Is the "problem" linux-side or windows ? Thanks for feedback! – PushT – 2017-11-20T08:17:30.753

1Why do you want to execute GUI on the server using terminal? What's the point? – Martin Prikryl – 2017-11-20T09:04:52.487

I use c++ & python for statistical calculations on ubuntu. I then visualize in MS Excel, and I cant really choose differently. Have scripts to automatize Excel. Only thing I need to do is have the app output copied to windows with scp, and then trigger the script to open Excel and visualize. Had Excel 2003 on wine, but it is not sufficient now. Managed to install Excel 2013 on wine, but it was crapping out on me. Calc totally different in key aspects, and my colleague is a master in MS Excel. I don't really care how the script is triggered, but it has to run script and excel automatically. – PushT – 2017-11-20T15:25:00.853

Is your SSH running as a service? I remember several years ago I had to check "allow service to interact with desktop" in some other service configuration (services.msc…) to make it behave more like a regular application. I forgot if the goal was to open a window, interact with already existing one or something else. This was long before Windows 10 though, probably in XP era. The point is: any service is intended to run strictly in background, I think. At the time "allow service to interact with desktop" was a way to loosen this restriction. I don't know if it's possible in modern Windows. – Kamil Maciorowski – 2017-11-21T19:10:44.500

Answers

1

Not sure if it will work for all combinations of windows/linux

I wanted for logged windows user to see what ssh-ed user is doing, and vice versa, I needed for ssh linux session to "see" programs that it started in foreground.

So only way i got it to work was for that logged windows user and linux ssh user are the same, and that windows user started its own ssh with command C:\OpenSSH\sshd.exe -f C:\wherever\sshd_config

If sshd was started as a service, or as a scheduled task, it didn't work.

Hope it helps someone

Luka Vladika

Posted 2017-11-20T02:24:27.860

Reputation: 11