Is personal cloud computing an option?
by Guido España
November 8, 2019
Under the rain in San Jose
Walking in San Jose, Costa Rica in rainy season is a glorious feeling. The rain is torrential but warm, and the streets become streams. This wonderful feeling went away two days later when I had to use my laptop to finish my slides for the presentation I was giving the next day. The black and unresponsive screen made me realize that some of the rain in San Jose had probably reached my laptop in my book bag, messing something up in there. My laptop eventually came back to life 24 hours later, but those hours were horrible.
I back up all my work to dropbox, so there I wasn’t concerned about losing data, instead I was worried about running some R scripts and compiling latex code to finish the presentation. While I could use someone else’s computer, this meant I needed to setup all the dependencies and libraries to compile my presentation. People are usually busy in conferences because they are all trying to finish their presentations or trying to get some work done, so I didn’t feel comfortable borrowing a computer for that long. Instead, I focused on my phone. Unfortunately, running R scripts on an iPhone is an impossible task, and while I found some latex compilers on the cloud, it didn’t seem like it would work with my workflow. So, what could I have done hadn’t my computer come back to life?
Coding on the cloud
Coding on a phone is almost like coding on a tablet. Carrying a tablet for work travel would be much more convenient than a laptop, and it might be easier to keep away from the water. However, I have been trying unsuccessfully to justify the purchase of a tablet for work use for a while now. The problem always seems to be the same: how would I code in a tablet? Yes, there is pythonista to write some python code, but it’s not good enough, and has multiple limitations. For other programming languages, I am pretty much hopeless. The only alternative I have found is to code on the cloud. I have been avoiding this option for a long time because I don’t always have access to the internet when I am traveling. But I realized that usually in those situations I am not doing heavy coding. So, assuming that I will only code when I’m connected to the internet, I started to think if cloud computing was a good alternative to code on a tablet or on a phone.
The benefits
There are a couple of benefits of having a computer on the cloud. The most important one is that I could have a computer that’s always accessible. I have previously used teamviewer to access my computer from my phone, but it has poor resolution and it tends to lock me out. So, an always accessible computer would be nice. The second benefit from a cloud computer is to have everything setup and ready. For instance, I could setup a cloud computer with dropbox and all the libraries and packages needed for my research. The third benefit is knowledge. Learning to setup a computing instance on the cloud would be a great learning exercise.
The cons
There are obvious cons to a cloud computer. First, opening the computer to remote access means less security. My computer could get hacked and I could lose my data. Second, relying on a cloud computer as the only computing resource is just a bad idea. What if I’m coding on a train and I lose internet connection? All the effort would be lost. Speed is another problem because poor internet connections would lead to poor performance, mostly if I want to access my computer with a graphical interface.
Diving into it
Giving that the benefits out-weight the cons, I went for it. I decided to start with a small computing instance in AWS with 8GB of storage and 2GB of RAM. Yes, the specifications are not impressive (my phone has double that storage), but it’s a good start because setting it up on amazon aws is very easy and having it on amazon aws ensures that the computing instance is always on and secure. To set it up, I just clicked on ubuntu server and voilá.
Accessing the remote computer is just as easy as setting it up. At some point during the setup, there is a prompt about downloading ssh keys. These ssh keys are text files that allow my remote computer to know that it’s me who’s accessing the instance from my laptop, phone, tablet, etc. In my laptop, I saved this key in ~/.shh/amazonaws-test.pem, in my phone, I had to enter the entire text in my terminus app. With this key, I can connect to my amazon aws instance without typing a password or anything like that. It’s secure because to access my remote computer, someone would need to have exactly the same file. So, my computer is safe as long as I keep this key secure.
Although the goal of this experiment is to access my computer from a tablet or a phone, I started with my laptop because it’s easier, and I don’t have a tablet yet. From my computer, I opened the terminal app and typed the following command (replacing ipaddress for the real ip address)
ssh -i ~/.ssh/amazonaws-test.pem ubuntu@ipaddress.compute.amazonaws.com
The IP address can be found in the main amazon aws dashboard. Just select the instance and click on connect, then all the necessary commands will be displayed. Then, I just updated the system with sudo apt-get update
and installed R using sudo apt-get install r-base-devel
. And that’s enough for me. I can just log in to my computer from any location and run any code I need on it. I can even compile LaTeX documents from this instance using the terminal window and a command line text editor, like emacs, vim, or nano. However, things can get better. Ideally, I would like to access a graphical user interface (GUI) with a desktop environment, so I could have a laptop-like experience.
Desktop environment
While the server does not have a desktop environment by default, because it doesn’t have a display, one can install whatever desktop environment one desires. I installed XFCE because it’s modern and fast. Installation is as easy as typing
sudo apt-get install xfce-desktop
This command will install all the necessary components to run an xfce desktop environment, which I could then access remotely. There are two components needed to connect to the remote computer with the desktop environment, a VNC server and a VNC viewer. The VNC server runs the desktop environment in the server, while the VNC viewer allows computers to access remotely the desktop environment (e.g., screen sharing and teamviewer).
In ubuntu, I decided to install vnc4server
by typing
sudo apt-get install vnc4server
Vnc4server requires a password to connect. This requires typing vncserver :1
on the terminal and typing the password. This also creates all the configuration files for vncserver. To kill the process, type vncserver -kill :1
. Then, go to the vnc configuration files and change the .xstartup
file:
cd ~/.vnc
nano xstartup
Finally, paste the following to the .xstartup file
#!/bin/sh
unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
And that’s all I had to do to setup the vnc server. After that, I just re-ran the vnc server with vncserver :1 -geometry 1024x1080
.
The vnc server runs on the port 5901, but opening that port creates a bunch of security issues, because anyone could try to access it by brute force. The vnc server will lock if three failed attempts to login are made, but that means it would lock me out as well. So, I decided to use port forwarding instead. It’s fairly easy. Basically, it just requires an ssh connection with the following options:
ssh -L 5901:localhost:5901 -i ~/.ssh/amazonaws-test.pem ubuntu@ipaddress.compute.amazonaws.com
Then, I can connect to localhost:5901
from a vnc viewer to access my remote computer. On my macbook pro, I use screen sharing; from my fedora laptop, I use tigervnc. The quality is actually pretty good. It looks much better than when I use teamviewer to access remotely my desktop or laptop. It feels as if it were a local computer.
Phone or tablet access
From my phone, I used terminus to access my remote computer. To access the desktop environment, I used port-forwarding on terminus and the app vnc viewer. I’ve struggled to keep my connection alive on terminus when I leave the app. I’ll keep working on that, maybe I’ll try blink, which many people recommend. The same configuration works for tablets. I tried this procedure on my wife’s iPad mini and it works fine.
Next steps
Now that I have been able to set up a remote computer on amazon aws, I am thinking about setting up my own server at home. I don’t have any experience with this, but it sounds like a fun challenge. The advantage is that I can have more storage and have all my dropbox files, so that any change I make will show up on my laptop or desktop computer at work.