sanketbajoria / ssh2-promise

ssh with promise/async await and typescript support
https://www.npmjs.com/package/ssh2-promise
MIT License
148 stars 25 forks source link

X11 forwarding may fail if X server is listening on a Unix Socket #64

Closed jeremyfix closed 3 years ago

jeremyfix commented 3 years ago

Hello,

for x11, it might be that the X server is listening on a Unix socket and not a TCP port and host (see the ssh2/issue#1053 ).

For that case to work, we need to connect to the X server with the socket, for example :

xserversock.connect('/tmp/.X11-unix/X0');

rather than

xserversock.connect(6000, 'localhost');

which is actually the code used in src/sshConnection.ts#L265 which means the x11 call will fail if the X server is using a Unix socket.

I do not know what is the best way to parametrize this, maybe by providing an option to the SSH2Promise.x11 or an option of SSHConfig given to the constructor ? Actually , I do not know if it is possible to programatically determine if the X server is using a socket or a port and on which ones it is listening.

Best. Jeremy.

sanketbajoria commented 3 years ago

@jeremyfix

To support this, I think, we have to support both, we have to change sshConnection.ts#L265. So that, if unix socket has been passed, then, connect to client as below

xserversock.connect('/tmp/.X11-unix/X0');

Let me try to fix it by today.. Hopefully tomorrow, you will get a new build

sanketbajoria commented 3 years ago

@jeremyfix please refer to this commit b8aebe5

Can you please confirm, if it fixes your problem.

sanketbajoria commented 3 years ago

@jeremyfix ssh2-promise@1.0.1 has been published. I have introduced new attribute in sshConfig named x11 to solve your problem image

jeremyfix commented 3 years ago

Thank you for your help ;

Sorry for not being able to test, I finally moved to ssh2 directly in my project rather than using ssh2 promise. I then have to write my own promise but I had the feeling I would better learn to code directly with ssh2 rather than with an abstraction.

I close your issue. I think your commit did allow now to handle the case I was mentioning.