3

I was playing with my phone (that runs a Linux/X stack) last night and I managed to ssh into my desktop and run an application and have it show up on my phone. It was awesome.

Today I'd like to sort of do the opposite. I want to view an application running on my phone on my PC. I could install a SSH server on my phone but I frankly don't fancy that purely for security reasons. I want this to be initiated from my phone.

Is there a way to connect from my phone and tunnel the PC's X connection back to the phone and then run an application on the phone that show on the PC?

3 Answers 3

5

"reverse ssh tunnelling" or "remote port forwarding" is your friend.

issue this on the phone

ssh -f -N -X -R 5555:localhost:22 desktop_user@desktop

then, on the desktop this

ssh -X -p 5555 phone_user@localhost

1
  • 1
    Requiring the user to SSH in both directions violates the constraint of not running an SSH server on the phone.
    – inetknght
    Mar 7, 2019 at 23:02
2

If I understood it correctly you just need to use the DISPLAY variable on your phone to redirect the applications display to your desktop.

On your desktop:

xhost +phone_ip

On your phone:

export DISPLAY=desktop_ip:0

start app

3
  • 1
    But I need this tunnelled over SSH. And to the PC the connection would look like it was coming from a localhost (where the ssh server is) so I'm not sure it needs xhost. My understanding of this gets a bit blurry because I don't know what TCP port X runs on. I don't know what I'm supposed to forward and I don't know how to construct the DISPLAY=... statement on the phone to use the forwarded port.
    – Oli
    Nov 4, 2010 at 10:12
  • Actually I should notice that with GDM X is started with "-nolisten", you can check that with: ps -ef | grep nolisten. You will need to change that to start with. I am not sure how to change it. Once X is listening I believe the TCP port is 6000 + display nr Nov 4, 2010 at 10:30
  • Urgh. At that rate it might just be easier to run a SSH server on my phone that only binds to localhost. From there I could SSH to my desktop and run another SSH connection back (tunnelled over the first) with X forwarding and in that run the program. Sounds nasty.
    – Oli
    Nov 4, 2010 at 11:02
0

Reviving this old thread just to provide modern solutions for old problems:

I'm not sure how innards of scrcpy work, but it surely is something worth checking out - it's an open source project providing BOTH display AND control over your Android device.

Aside from the basic "show me phone's screen" it supports many other things like gestures, hotkeys, recording, wireless (!) control of android through adb and many other features. Additionally another project (linked on the github page - sndcpy) allows audio forwarding. This is purely a host PC program, and only requires debugging enabled on the target device. IIRC everything works over ADB (so Android only???).

There is no visible lag when running through USB on my Ubuntu 20.04 Lenovo <-> Android 10 Huaweii P20Pro on full resolution and maximum FPS, and on wireless there are minor drops to 15 FPS and minimal input lag. I successfully managed to play a game on my phone through my notebook's mouse and keyboard.

Main adventages:

  • multiplatform - scrcpy works on linux, windows and mac
  • host OS only - minimal setup on adroid is required (allowing USB debugging)
  • works out of the box
  • what a quality!
  • open source

To be fair, this doesn't exactly satisfy the "initiate from the phone" condition, but I'll post this answer anyway, only because the scrcpy is so powerful in what it does and deserves more recognition.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .