Screen(ing) Your Desktop Over the Web
The other day (read: a few months back), one of my friends asked me to “show” him how to compile software from source on Linux. I’ve quoted the word because he literally wanted to “see”. The problem was I’m in Gurgaon, while he’s in Mumbai. Add to the fact that I was at work at the moment, so forget the availability of a Web cam in the vicinity.
Now, how was I to share my computer screen so that he could see what I was up to? I know Skype has features that make this sort of a job possible — but I don’t use it.
During a sudden requirement like this the combined power of Open Source and Google came to the rescue, as always. The solution I was suggested was a utility called
screen — which most of the times is installed by default on most Linux distributions (if not, we all know how to install software, right?). This one is the exactly what we needed at the moment — a utility that would let him view my screen on his system over a network (read: Internet, in our case).
If you and I are on the same path, then you might have guessed already that the only way for him to connect to my computer is using an IP address. Now comes the next issue: I’m behind a NAT, and so is my friend. Well, most people using ADSL Internet connections are. So, there’s no way my friend could connect to my machine’s IP address to view my “screen”.
Under the circumstances the only possible way is to create a secure tunnel over the Internet so that he could connect to my machine. I used SSH to create the tunnel — that is, basically forward a port of my computer over the Internet to him so that he could connect.
Let us assume the IP address of my system is 192.168.0.12. The IP address for my ADSL router is 220.127.116.11.
The next step is to forward one of the ports from my system to the ADSL router — this is where my friend will connect.
Run the following command to forward my local port (say, 5000) to the public IP of the router:
ssh -R5000:localhost:22 -Nf 18.104.22.168
In the next step I’ll share my terminal screen as follows:
screen -S ajeet
S means share, and
ajeet is the name I’ve given to the terminal screen I’m sharing currently.
Next I’ve to enable multi-user mode so that my friend is able to access my screen (that is, view whatever I’m doing on it). So now, following the earlier
screen command, press
Ctrl+A and key in:
That’s it. Now anyone who has details of my router’s IP address, it’s password, and my machine’s port number can connect to my “screen”. The steps for my friend are as follows:
Using the above command he connects to the ADSL router.
ssh localhost -p 5000
Using the above command he’s now connecting to my “localhost” (that is, my machine), whose forwarded port is 5000.
Finally, to view my screen, he simply has to run.
screen -x ajeet
That’s all. Now whatever I’m typing on my screen sitting here in Gurgaon, my friend is able to view it from Mumbai. All this over the Internet, securely.