Living in a remote host
2019-04-11
Derek Zhou
In my last blog post about homedir, I talked about how I plan to re-organize my homedir to find my things quickly. There is also a problem I didn't talk about: I have many devices and computers, with various levels of connectivity, so I have many home dirs. Because of the connectivity and robustness requirement, NFS mount home dir is not realistic, so how would I keep all the home dirs in sync? The answer is quite simple: I use one home dir as my primary one; everyone else does not hold real data. The one home dir is not on any of my desktop or laptop computers, but on a virtual server in the "cloud." I call it my Homebase.
Why remote
Among all the computers I own, the virtual one has the best connectivity, bar none. It has a permanent IP, 100% on line, well maintained with a disaster recovery plan. It is far from the fastest one, but it is the most reliable one. If I have to pick one for my Homebase, reliability is so much more important than other factors.
However, I am not at the Homebase; my computers access my Homebase via the network. Beside application-specific protocols such as HTTP or IMAP, the one connection method for the majority of my data exchange need is SSH. With SSH, there are many ways to connect to the Homebase; what I do depends on the connectivity situation:
- a fast and reliable network to the home base.
- a slow but functional connection to the home base.
- no or poor connectivity.
I cannot do much in the third case, but hopefully, I won't be stuck in there for long. In the first case, I should be fully productive, and in the second case, I can make things progressing.
One protocol, many methods
SSH is a very versatile protocol. I have public-key accesses setup from all my digital devices to my home base, so it is both secure and convenient.
shell based
90% of the case All I need is a couple of shells, one of them running Emacs. I read/write my emails, work on my programs or documents, run tests, and admin my machines in shells.
Persistent Emacs
I do the majority of my work with Emacs, terminal Emacs, particularly. Emacs has a daemon mode, so my emacs session lives on even if I broke off from my Homebase for whatever reason. I'd ssh in and connect to my original emacs session.
Persistent shell
I also use the command line extensively. Gaining shell access is not hard; I also prefer to have long-lived shell sessions. The tool I use is Dtach. With a little bit of scripting, I have several long-lived shells, each dedicated to one line of tasks, and I can switch among them.
fast network usages
On a fat pipe (1Mb/s or above) with low latency (20ms or lower), many other things are possible:
Persistent desktop session
I don't do it anymore, but it still can be done. The tool I used is called X2Go. The session lives on the server, and I can reconnect from anywhere.
Persistent GUI
A whole desktop session is often too heavyweight and feels alien from your local desktop. What I usually do these days is single application forwarding, and the tool I used is called xpra. Again, the session is persistent, and the application will not get killed if I broke off from the network, and I can reconnect and resume the GUI application from anywhere I want. The added benefit is the application window is locally managed by the local window manager, and I feel almost the same as working locally.
Local GUI access remote data
Unlike shell access, GUI access from remote is still not the same as local GUI, no matter how fast the connectivity is. Sometimes it is just unresponsive enough to be annoying, or look somewhat ugly or lack some functionalities such as sound, printing, or Chinese input. So, unless there is a GUI tool, I can only access remotely (very few), I prefer to use local GUI applications. I have to access remote data, though, since all vital data live in the remote host. The way I use is sshfs. With it, I can mount the remote Homedir locally by:
sshfs homebase.XXX.YYY: homebase
Then all my remote files show up in the homebase/ dir. That's how I edit my libreoffice documents or gimp images or graphics.
slow network applications
Sometimes you are stuck with a slower network with long latency (cellular, cross-continent, etc.). The above may not work to your satisfaction. The below applications can also work in the fast network case, of course, but they also work good enough with a slower or even jitterish network.
SOCKS proxy
My remote Homebase also gives me access to a private network that people have no access from the outside. The primary network interface is HTTP/HTTPS, and most browser support SOCKS5 proxy which I can build one using ssh:
ssh -D 1080 homebase.XXX.YYY
Then point my browser's proxy to socks://localhost:1080, no additional software required on the client-side.
git
Git can work through ssh, and it is bandwidth conservative. I can clone/pull a git repository residing on the Homebase and work locally with no connectivity at all, and push back when I am online again.
rsync
Rsync is very bandwidth conservative. For the projects that git does not have much benefit, such as non-text files, I Rsync them from and to my Homebase. I can work locally without connectivity and sync back when I get back online.
conclusion
I still do browsing or social media without going through my Homebase. That would be awkward, and it does not require storing vital state locally anyway. But for everything else, I try to do it from my Homebase, so I can always do it in the one way I am most familiar and comfortable with, which is terminal Emacs most of the time. I know there are fancy tools, even Emacs can be prettier through GUI, but I value security, persistence, and consistency more than fancy at this time of my age.