Open toto6976 opened 3 months ago
First, independently of scrcpy, can you access your remote computer (on which the remote device is connected) from your local computer using ssh?
Yes i can access the remote computer from my local computer via ssh. Remote house : pc with ssh server, smartphone. Local house : pc with ssh client.
And scrcpy works in the remote house from pc (witch one having the ssh server) to smartphone.
OK, the describe what you did and what errors you got. Only use IP for know (don't use DNS to avoid additional possible issues).
I am trying to understand how the ssh tunnel works
# local 5038 --> remote 5037
# local 27183 <-- remote 27183
ssh -CN -L5038:localhost:5037 -R27183:localhost:27183 your_remote_computer
1/ i don't understand the ports. 2/ in my situation, what is remote computer and the localhost.
From thé pc 192.168.0.251 I tried ssh -CN -L5038:192.168.0.251:5037 -R27183:192.168.0.251:27183 mysshserveur@dyndns.net pxxxx
hostname contains iinvalid characters
1/ i don't understand the ports.
5037 is the port adb is listening on on your remote computer
If you create a local port redirection (-L5038:localhost:5037
), this means that accessing your local port 5038 will redirect you to localhost:5037
from the other end of the tunnel (so on your remote computer). In other words, from your local computer, localhost:5038
is your_remote_computer:5037
.
2/ in my situation, what is remote computer and the localhost.
My smartphone is identified on the local network at 192.168.1.14 I have an ssh server open on 192.168.1.72.
What is the public address IP if your ssh server (as viewed from your client computer, 192.168.1.72 is the local address, not the public one)? That IP is your_remote_computer
.
localhost
is localhost
, nothing to change.
Hi 192.168.1.72 is the local ip adress of my pc on wich my ssh server is located. Of course it have an ip public : 65.xx.xxx.yyy. Is this PC the remote PC ? Is 192.168.0.251 the localhost ip ? I think i don't really understand port redirection. So i keep 5037. Then here is the new code ssh -CN -L5037:192.168.0.251:5037 -R27183:192.168.0.251:27183 65.xx.xxx.yyy pxxxx Is it OK ?
5037 is the port adb is listening on on your remote computer
So the 'remote computer' is the one witch the ssh server is installed. It means on the same LAN as the smartphone ?
Your server: 65.xx.xxx.yyy (machine with local ip: 192.168.1.72). Your client: localhost (machine with the local ip: 192.168.0.251).
I assume both computers are on Linux.
From the client, execute:
ssh -CN -L5038:localhost:5037 -R27183:localhost:27183 65.xx.xxx.yyy
# keep this open
From another terminal on the client:
export ADB_SERVER_SOCKET=tcp:localhost:5038
scrcpy
I think i don't really understand port redirection. So i keep 5037.
One problem is that if your local computer also has an adb server running, 5037 is already used locally.
ssh -CN -L5037:192.168.0.251:5037 -R27183:192.168.0.251:27183 65.xx.xxx.yyy pxxxx Is it OK ?
No, you must keep localhost
. The remote direction will not work on another interface by default.
And what is your pxxxx
?
If your ssh server listens on a port different of the default one (22), you can pass an option -pxxxx
(the -
is missing, probably a typo in your comment).
Yes , it's -pxxxx sorry.
One problem is that if your local computer also has an adb server running, 5037 is already used locally.
On the localhost computer (192.168.0.251) ? So an 'adb kill-server is OK ?
One problem is that if your local computer also has an adb server running, 5037 is already used locally.
'Local computer' it means localhost computer (192.168.0.251) ?
Yes, the client.
("localhost computer" is confusing, since every computer is localhost/127.0.0.1)
From another terminal on the client:
export ADB_SERVER_SOCKET=tcp:localhost:5038 scrcpy
I write "scrcpy" or "scrcpy --tcpip 192.168.1.14:5555 ?
OK i think i understand.
A last question : can i keep the smartphone screen off ? What should i add to the command line you gave me ?
I write "scrcpy" or "scrcpy --tcpip 192.168.1.14:5555 ?
As you like (it depends if it is connected over USB or not). From the client, you can use adb devices
to list the remote devices (and adb connect
, etc. as usual).
can i keep the smartphone screen off ?
Yes: scrcpy --turn-screen-off
.
It is not connected over usb. So i write scrcpy --tcpip 192.168.1.14:5555 ?
as I am not in the house today where the smartphone is located, will it ask me to associate the 'localhost' PC or everything happens as if I am using the PC (remote) with which I am using it? had associated?
So i write scrcpy --tcpip 192.168.1.14:5555 ?
Yes. From a terminal where ADB_SERVER_SOCKET
is correctly defined:
export ADB_SERVER_SOCKET=tcp:localhost:5038
OK. I trie today.
Everything is ok.
I tried with the dyndns adress and it seams ok too.
can we use scrcpy on 4G if the wifi connection cuts out for one reason or another?
Le lun. 2 sept. 2024 à 09:40, Romain Vimont @.***> a écrit :
Yes. From a terminal where ADB_SERVER_SOCKET is correctly defined:
export ADB_SERVER_SOCKET=tcp:localhost:5038
— Reply to this email directly, view it on GitHub https://github.com/Genymobile/scrcpy/issues/5254#issuecomment-2324032065, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMWAAOQ7H5AXUQM6Z4KN47LZUQJABAVCNFSM6AAAAABNO4K626VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRUGAZTEMBWGU . You are receiving this because you authored the thread.Message ID: @.***>
Hi,
This morning, i can't connect adb !!
adb: failed to check server version: protocol fault (couldn't read status): Connection reset by peer
channel 2: open failed: connect failed: Connection refused
I start adb on the ssh server. Everything is ok ! Why ???!
I start adb on the ssh server.
Because your client adb connects to the adb daemon, which normally runs on the same machine, but here it runs on the remote machine (and the client and daemon connects through the ssh tunnel).
In other words, when you run adb devices
, normally, your process connects to the ssh daemon (listening on localhost:5037 by default). But here, you specified to connect to localhost:5038, and the local port 5038 is forwarded to the remote port 5037, so your local adb client connects to the remote adb daemon. If the daemon is not running, then there is nothing to connect to.
ok. Do I have to reconnect the device via usb? or an adb connect device_ip_address:5555 is enough
It depends if you rebooted the device. It must be connected over USB at least once after each device reboot to execute (directly or indirectly) adb tcpip 5555
.
Another thing: I have two devices on two different addresses. They each have a different tcpip port. Device 1 tcpip 5555 Device 2 tcpip 5556 When I change devices, only device 2 requires a usb reconnection to work. The other no?!? I don't know what to do. Device 1 is a normal Samsung, device 2 is an OS 11 lineage.
It depends if you rebooted the device. It must be connected over USB at least once after each device reboot to execute (directly or indirectly)
adb tcpip 5555
.
No, the device is not rebooted
They each have a different tcpip port
Why do you use different ports? Just use 5555 (the default) for all devices.
When I change devices, only device 2 requires a usb reconnection to work. The other no?!? I don't know what to do.
I'm not sure to understand.
I start adb on the ssh server.
Because your client adb connects to the adb daemon, which normally runs on the same machine, but here it runs on the remote machine (and the client and daemon connects through the ssh tunnel).
In other words, when you run
adb devices
, normally, your process connects to the ssh daemon (listening on localhost:5037 by default). But here, you specified to connect to localhost:5038, and the local port 5038 is forwarded to the remote port 5037, so your local adb client connects to the remote adb daemon. If the daemon is not running, then there is nothing to connect to.
ok. It's not practical at all but hey...Isn't there a way to do it differently?
They each have a different tcpip port
Why do you use different ports? Just use 5555 (the default) for all devices.
When I change devices, only device 2 requires a usb reconnection to work. The other no?!? I don't know what to do.
I'm not sure to understand.
https://developer.android.com/tools/adb Each emulator uses a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections. For example:
Emulator 1, console: 5554 Emulator 1, adb: 5555 Emulator 2, console: 5556 Emulator 2, adb: 5557 and so on.
It's not practical at all but hey...Isn't there a way to do it differently?
It's just some hacks to connect to the adb daemon as if it were local (i.e. running on the same machine).
The user-friendly solution would be to add server/client features to scrcpy, which is out-of-scope.
ok, so only
adb tcpip 5555 adb connect device_ip_address1:5555 adb connect device_ip_address2:5555
then I can switch from one to the other by simply changing the address: scrcpy --tcpip adresse_ip1:5555 or scrcpy --tcpip adresse_ip2:5555
It's not practical at all but hey...Isn't there a way to do it differently?
It's just some hacks to connect to the adb daemon as if it were local (i.e. running on the same machine).
The user-friendly solution would be to add server/client features to scrcpy, which is out-of-scope.
I don't understand absolutely anything! We'll leave it like that for the moment.
I'm trying to access, via adb and scrcpy, a remote android device and I don't understand why a simple reverse port forwarding of the port 5555 via ssh doesnt work. ( While, when the android dev is in the local network, I can easily connect to it via adb connect android_local_ip:5555
)
I have an exposed-to-internet ssh server at, let's say, ssh_ip:ssh_port
and a remote android device on another network. I installed termux on such android device and installed openssh (and other packages) in termux, set up public keys and then launched from the android's termux:
ssh -p ssh_port -N -f -R 5555:127.0.0.1:5555 user@ssh_ip
such that at the ssh server I would run adb connect 127.0.0.1:5555
and reach the android device.
It seems that the tunnel works as intended as I tried with openbsd netcat listening on the termux. But the ssh server cannot establish the adb connection via the forwarded endpoint.
Adding -vv
in the ssh commands I can read a bunch repeting lines that starts around line 100-ish
Any help? Feel free to ask anything.
@kuolemaaa Read https://github.com/Genymobile/scrcpy/blob/master/doc/tunnels.md#ssh-tunnel
@rom1v I've read it already but I don't understand why it should be useful to me since I cannot even connect to adb yet. I managed connect a remote computer to an android dev using another device in the middle like so:
android | local |laptop | inet | ssh server (me) |
listening| |adb listening :5057 | | |
:: :5555 |<--------|adb connect | | |
____ ____| |ssh -R 5057:127.0.0.1:5057|-------->| adb shell |
^ |
|____________________________________________________________|
But this configuration is no use to me.
What I need to do is:
android | inet | ssh server (me)
listening :5555 | |
(termux) ssh -R 5555:127.0.0.1:5555 |---------->| adb connect 127.0.0.1:5555 ; adb shell
^ |
|_________________________________________________________|
In this configuration the tunnel actually works (tested letting netcat listening on the android device and reverse-port-forward to the ssh server)
but it doen't work forwarding port 5555 and running adb connect 127.0.0.1:5555
on the server.
What I got is this block of messages, repeating, changing connection port at every attempt:
debug1: client_input_channel_open: ctype forwarded-tcpip rchan 1 win 2097152 max 32768
debug1: client_request_forwarded_tcpip: listen 127.0.0.1 port 5555, originator 127.0.0.1 port 41003
debug1: connect_next: start for host 127.0.0.1 ([127.0.0.1]:5555)
debug2: fd 4 setting O_NONBLOCK
debug2: fd 4 setting TCP_NODELAY
debug1: connect_next: connect host 127.0.0.1 ([127.0.0.1]:5555) in progress, fd=4
debug1: channel 0: new forwarded-tcpip [127.0.0.1] (inactive timeout: 0)
debug1: confirm forwarded-tcpip
debug1: channel 0: connected to 127.0.0.1 port 5555
debug2: channel 0: read failed rfd 4 maxlen 32768: Broken pipe
debug2: channel 0: read failed
debug2: chan_shutdown_read: channel 0: (i0 o0 sock 4 wfd 4 efd -1 [closed])
debug2: channel 0: input open -> drain
debug2: channel 0: ibuf empty
debug2: channel 0: send eof
debug2: channel 0: input drain -> closed
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: chan_shutdown_write: channel 0: (i3 o1 sock 4 wfd 4 efd -1 [closed])
debug2: chan_shutdown_write: channel 0: shutdown() failed for fd 4 [i3 o1]: Transport endpoint is not connected
debug2: channel 0: output drain -> closed
debug2: channel 0: rcvd close
debug2: channel 0: send_close2
debug2: channel 0: send close for remote id 1
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: 127.0.0.1, nchannels 1
android | inet | ssh server (me) listening :5555 | | (termux) ssh -L 5555:127.0.0.1:5555 |---------->| adb connect 127.0.0.1:5555 ; adb shell ^ | |_________________________________________________________|
Typo in this diagram: you probably meant ssh -R
on the left (but it was correct in your previous comment).
Your commands and redirections look correct to me. I don't know why it does not work.
channel 0: read failed rfd 4 maxlen 32768: Broken pipe
Maybe an issue with the version/build configuration of OpenSSH for termux? Possibly related:
android | inet | ssh server (me) listening :5555 | | (termux) ssh -L 5555:127.0.0.1:5555 |---------->| adb connect 127.0.0.1:5555 ; adb shell ^ | |_________________________________________________________|
Typo in this diagram: you probably meant
ssh -R
on the left (but it was correct in your previous comment).Your commands and redirections look correct to me. I don't know why it does not work.
channel 0: read failed rfd 4 maxlen 32768: Broken pipe
Maybe an issue with the version/build configuration of OpenSSH for termux? Possibly related:
* [Connection drops after authentication PowerShell/Win32-OpenSSH#1924](https://github.com/PowerShell/Win32-OpenSSH/issues/1924) * [scp giving EOF and exit status 1 tailscale/tailscale#8592](https://github.com/tailscale/tailscale/issues/8592)
Yea, typos on the messages, I meant -R
.
I will look at your linked issues.
By the way I managed to use adb+scrcpy over internet using a tool of network mesh. I really dont know why my ssh solution doesnt work. Maybe termux fault? I dont know.
Good morning, I cannot connect to my smartphone when I am outside my home. I read the doc on 'ssh tunnel' but it doesn't work. I suppose i don't understand. Can you tell me what to do ?: the commands I pass must be wrong.
My smartphone is identified on the local network at 192.168.1.14 I have an ssh server open on 192.168.1.72. The PC with which I want to access the smartphone is in 192.168.0.251 in a other town. I open dyndns adresse on livebox to my ssh serveur.