0

I'm currently away from home, and I would like to access my iMac which is turned on in my place. I set up the mac screen sharing before I leave, but something went wrong, and I can't access it from my MacBook. My home network is accessible via ssh on a Raspberry Pi. I would like to know, if there is any way to access my iMac and set up a ftp or vnc server on this one via the RPI. For example, is there any linux software that could allow me to acces another client on the same network via VNC. If it's possible, then I could try to access the RPI from my current place.

EDIT: After @baf comment, here are all my open ports on the iMac:

PORT      STATE    SERVICE
3/tcp     filtered compressnet
22/tcp    open     ssh
88/tcp    open     kerberos-sec
222/tcp   filtered rsh-spx
513/tcp   filtered login
898/tcp   filtered sun-manageconsole
1055/tcp  filtered ansyslmd
1083/tcp  filtered ansoft-lm-1
1455/tcp  filtered esl-lm
2725/tcp  filtered msolap-ptp2
3370/tcp  filtered satvid-datalnk
3801/tcp  filtered ibm-mgr
5900/tcp  open     vnc
8873/tcp  filtered dxspider
9001/tcp  filtered tor-orport
9110/tcp  filtered unknown
10628/tcp filtered unknown
13782/tcp filtered netbackup
20221/tcp filtered unknown
31038/tcp filtered unknown
32772/tcp filtered sometimes-rpc7
32776/tcp filtered sometimes-rpc15
40911/tcp filtered unknown
44176/tcp filtered unknown

EDIT: After baf answer, I update what I currently did: I execute that command: ssh -L 5999:192.168.1.10:5900 pi_host_over_internet So if I understand correctly the VNC port from my iMac is accessible throught the port 5999 from my Pi. Now to connect to it from my current location, I need to connect with a VNC client to 'pi_host_over_internet:5999'. I try this, but obviously, it doesn't work because the port 5999 isn't forwarded to the Pi on his router.

EDIT: Clarifying my setup:

What I have right now, where I am (UK):

MacBook connected to a public WiFi

What I have in my home (France):

Imac, local ip:`192.169.1.10`, port 5900 listenin to VNC, port 22 listening to SSH
RPI, local ip:`192.168.1.12`, port 22 listening to SSH
router accessible at `mydomain.com`, port 22 forwarded to RPI@`192,168.1.12:22`

EDIT: Here is what I get after @baf answer:


I would take any suggestion, so feel free to propose anything.

2
  • Scan your iMac from Pi with nmap to see if there are any ports open. If any service is accessible from Pi you should be able to port forward it through ssh to outer world.
    – baf
    Apr 3, 2015 at 20:49
  • Thanks for your help, the VNC port is open on the iMac (as updates in the question), but I have no idea how I can VNC it throught my PI from here. Any help or suggestion ? Apr 3, 2015 at 23:30

1 Answer 1

0

On you local machine (outside your network) you should run ssh client with following parameters:

ssh -L 5999:imac_host:5900 pi_host

I chose 5999 for local port but it could be any port. You only have to make sure it is not used by any local service. Substitute imac_host and pi_host with ip addresses.

When you successfully connect with given command, vnc port 5900 from imac_host will be forwarded to your local machine port 5999.

Next you need to configure your vnc client on your local machine to connect to localhost at port 5999 (connect to itself at given port).

How it works

VNC server on you iMac is listening on port 5900 for incoming connections. VNC clients may connect to this port from other machines in your local network. As you don't have direct access to port 5900 on your iMac, you are using ssh to tunnel the connection from your computer over Internet through the router to iMac in your local network.

ssh opens port 5999 (could be any other port) on your current machine and listens on this port for connections. When you connect to this port ssh tunnels the connection (through ssh port 22) to your router and from the router establishes connection to iMac on port 5900. It is called port forwarding.


Your iMac also has ssh enabled. If you don't need vnc, but only want to copy a file, it should be possible to use scp. To make it simple you could try without any port forwarding. Just copy file from imac_host to pi_host. From Pi console run:

scp username@imac_host:path_to_file destination_file`

This will copy path_to_file file to destination_file in your current folder on Pi. Then you can repeat this step and copy file from Pi to your local machine.

12
  • Thanks again, I tried it, but as I thought, it didn't work, certainly because the port 5999 isn't forwarded to the PI on his router. I update my question to give more details, if you have any other idea. Thanks Apr 4, 2015 at 14:03
  • Port 5999 will be created on your local machine, not on Pi. You have to connect VNC to localhost (your current location), not Pi.
    – baf
    Apr 4, 2015 at 14:24
  • Ok, I tried that, it seems to work, but I'm asked for a password, my PI and iMac password are the same, but when I type it, it's failed. Have you any idea ? Is that the correct password I have to provide ? And I don't really understand how does it works, could you explain me a little bit please ? That would be awesome :) Apr 4, 2015 at 17:41
  • I updated my answer with short explanation. Regarding the password it depends on your setup. If you didn't establish special password for vnc server, you should be able to connect with your iMac admin credentials. It should also be possible to login to your iMac with ssh and set vnc password from command line. But I suggest you ask new question about this.
    – baf
    Apr 4, 2015 at 18:29
  • Ok, now you explained me how it should works, I understand why it doesn't. When I connect to SSH over internet, I can only do it on RPI, and then from this ssh connection I can open another to my iMac with its network adress:192.168.1.10. Apr 4, 2015 at 18:40

You must log in to answer this question.

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