NuSphere Forums Forum Index
NuSphere Forums
Reply to topic


Joined: 18 Mar 2019
Posts: 18
Location: Canada
Reply with quote
Yes, after my last reply, I noticed that you mentioned about open the Firewall port for the OpenSSHd from Cygwin, so I realized that you referred to run the whole SSH server and shell using Cygwin.

As I proved before, by executing the commands manually, it's possible to run the CLI debugger using the CMD, but needs that PhpEd, knows that is not a bash shell and send the correct sequence of command. I said this should be considered as Window Server 2019 and 2025, the SSH server is built-in and deployed on production servers, especially for Core deployments.

I know that you mention that PhpEd and these features are mean for developing. However, when something goes wrong on production, the debugger is an amazing tool to diagnostic and figure out an already deployed application without the need to download the whole application (code, database, data files) locally and redeploy on a stagging server. An even, the worst-case scenario, sometimes the misbehavior is not reproducible on staging servers, only on production.
View user's profileFind all posts by carloshSend private message


Joined: 18 Mar 2019
Posts: 18
Location: Canada
Reply with quote
I found another possible workaround; I am leaving the default shell to `cmd.exe`. But if I execute this command on the client:
Code:

ssh -p 22 -t user@host.domain.com "C:\cygwin64\bin\bash.exe -il"


I am landing on the bash shell. However, this cannot be use PHPEd because the Account UI for SSH Terminal Accounts, there is no option to add SSH "commands". If there were a choice, possible this could be a possibility.
View user's profileFind all posts by carloshSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8355
Reply with quote
If I read this right, you don't want to use cygwin's sshd (openssh) but windows sshd (openssh) because it's your prod and I guess you have some other integrations that relies on cmd.
May be you can setup a different User account for debugger and configure windows sshd to lauch cygwin bash automatically?
there is %programdata%sshsshd_config, where you can set
Code:

Match User username
            ForceCommand C:\Path\To\Cygwin\bash.exe --login

Does this solve the problem?

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 18 Mar 2019
Posts: 18
Location: Canada
Reply with quote
Thanks that put me on the right track but needed more work. I tried `ForceCommand` the shell directly but it didn't work. The SSH starts but debugger never completes. But if I call the .bat file of Cygwin it works. I think it's because if I call the shell directly it doesn't allocate a TTY terminal while executing. That is why when I executed form the ssh client command, I needed to include the -t parameter.

However, as before, with any of both methods, the SFTP for this user didn't work. I didn't want to create a new user only for SFTP. I did more research and I found that when the `ForceCommand` is used, it overrides any other requested command. This is the root problem, when a STFP request is called the subsystem tries to run the `sftp-sever.exe` command, but because we are forcing it into another command then this is not executed anymore on SFTP. So, I created a new .bat for Cygwin to detect when there was a command to start with. The original `cygwin.bat` contained this:
Code:

@echo off
setlocal enableextensions
set TERM=
cd /d "%~dp0bin" && .bash --login -i


The improved version named `cygwin-mod.bat` contains this:
Code:

@echo off
setlocal enableextensions

:: Capture the command into a variable safely
set "REQ_CMD=%SSH_ORIGINAL_COMMAND%"

:: If REQ_CMD is empty, it's an interactive login -> Go to Bash
if "x%REQ_CMD%x"=="xx" goto :launch_bash

:: Otherwise, it's an SFTP or other specific command request -> Execute it
%REQ_CMD%
exit /b %ERRORLEVEL%

:launch_bash
set TERM=xterm-256color
cd /d "%~dp0bin" && .bash.exe --login -i
exit /b %ERRORLEVEL%


Now on the `sshd_config` I have to be sure that contains these commands:
Code:

# override default of no subsystems
Subsystem   sftp   sftp-server.exe

Match User deb_bug
  ForceCommand C:\cygwin64\cygwin-mod.bat


With this, I can run SSH bash debugger on PHPEd and SFTP with the same user account, without forcing other accounts to use bash and/or potentially breaking the SFTP.

Now a final possible improvement request (annoying but not show-stopper). The TTY terminal used on PHPEd is very utilitarian and not practical or user friendly (or maybe not modern standard). For example, it doesn't allow copy and paste, some advance ANSI codes are not render (e.g. DIR_COLORS), the bash history is not saved, arrow keys up and down does nothing. All these works properly when SSH from Windows terminal, PuTTY or MinTTY so it's no problem with the shell.
View user's profileFind all posts by carloshSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8355
Reply with quote
Good job welding together two platforms -- the Unix-ported toolset and the Windows-ported version of OpenSSH originally built for Unix

As of TTY
-- the history -- it is handled on the shell (server) side, so it’s controlled by your Cygwin bash/zsh configuration files in the Cygwin home directory. You can add something like set +o history to your ~/.bashrc, or configure it globally via files in /etc/profile.d/ for all Cygwin users. First, check whether Ctrl+R works -- it triggers reverse history search. When you press it, bash should enter this mode. Start typing part of a previous command to search; if there are multiple matches, keep pressing Ctrl+R to cycle through them, then press Enter to select or Esc to cancel.

-- copy-paste -- they should work with Ctrl+Ins / Shift+Ins. You can also enable auto-copy so that selecting text with the mouse copies it automatically.

-- up-down -- the TERM variable may need adjustment in your ~/.bashrc. PhpED’s terminal supports only a subset of XTERM/XTERM256 features. If you have access to a Linux (like real linux or linux on windows) system, test it there and replicate any missing environment settings in your ~/.bashrc. It’s also possible that some required libraries for xterm support under Cygwin are not installed on the bash side.

-- DIR_COLORS -- it’s likely related to the same terminal capability configuration.

-- PuTTY supports a wide range of terminal types -- not just xterm, which may explain the difference. Find an xterm client created to test / validate shell and run it to validate your shell setup independently of both PuTTY and PhpED

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 18 Mar 2019
Posts: 18
Location: Canada
Reply with quote
I will try those keystrokes to see if I get any solution (Oh my god I have not used Ctrl+Ins / Shift+Ins since Windows XP). As I said, it not big deal, but when I am debugging CLI scripts, sometimes I want to copy the output for reference between runs.

Yes, I have a bunch of Ubuntu servers, it will compare how the default shell files are configured to see if there is something that can be adjusted on the Cygwin shell.

Thank you Dmitri for your help and guidance. Let's complete this issue here. I tried to document all the steps required in case somebody else has this issue too.
View user's profileFind all posts by carloshSend private message
Remote CLI SSH debug on Windows server does not from the IDE
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 2 of 2  

  
  
 Reply to topic