At the end, it pulls its own plug. After unmounting the phone, it sends "pkill sshd" over ssh, to terminate the phone's sshd server.
I use sshfs so that copying from phone to laptop is from mounted directory to local directory. Connection is like so:
# Mount the phone's DCIM ancestor directory locally over ssh.
# mg4: is an ssh host in ~/.ssh/config
sshfs mg4:/storage/emulated/0/ ~/mnt/mg4