Yesterday, after more than 1 year, Canberra went into a lockdown of 7 days! It is a saddening situation, but the efforts are for the greater good of community and everyone’s safety. So we are back at homes, working remotely like we used to be in earlt 2020. In trying out best to fit into the situation, we thought of sharing few tips and tricks for our readers.
Working at office vs home
In a typical work-place we have a computer, a desk, printer access, etc. However, the moment you switch to work at home you end up with far less resources. However, when we really think about it we are not in need of certain resources at the same time. For example, at home you’ll be e-working, hence no printing, filing, etc. Everything is online.
In case of us as researchers, we are required to work remotely and computing resources shall be accessed online. We live in a small apartment, so sharing the work-station on a desk (like in our feature photo) is not possible. So we came up with few workarounds to make life easier.
Setting up the compute environment
Most of our research happens in compute intensive environments. So just like in office it would be nice to have a Jupyter Notebook running somewhere to work as usual. For this we came up with the following solution. This is assuming you also have a VPN running and has an office/school network to work.
- In my case, I brought the office computer home (oh yeah!). And I also have a powerful one at home.If you have a home computer (or office) make sure they have static IP addresses. Usually office computers do have static allocations within the VPN. You can make yours at home with some settings in the router. For any TP-Link user the following is the settings screen.
- Setup SSH access to your computer. I am a Linux/Mac User for work (and always will be). So the commands to follow are pretty simple.
# Update ubuntu $ sudo apt update # Install openssh server $ sudo apt install openssh-server # Verify it is running $ sudo systemctl status ssh # Allow access through firewall (rarely needed for SSH) $ sudo ufw allow ssh
Now your system is ready to accessed using SSH from another computer (Your laptop or your home desktop if you’re accessing office. In that case you need to setup SSH server at office). Simply use
ssh username@ipaddress to enter the terminal. Often times this is very inconvenient so try the next steps!
- Faster SSH access to your Server/Office computer
Enter your laptop’s SSH config using the following command.
$ nano ~/.ssh/config
Now add the following entry.
host NAME hostname IP_ADDRESS_OF_SERVER user USERNAME_OF_SERVER
In my case, I am accessing my home computer from my laptop (which has a very nice screen+can work anywhere in home). Now you can simply type
ssh NAME and access the computer. No need to remember username/ip address or type them always. Now the problem is you need to enter the password of the server everytime. This can be annoying. Following is the fix!
In you client computer (one that you use to access server) type the following command. If you face issues here, you likely need to generate these keys (read more here).
$ cat ~/.ssh/id_rsa.pub
Then you can see your public key, which is used for secure connections such as SSH. You’ll see something as follows. I have of course truncated for simplicity.
ssh-rsa SOME GIBBERISH HERE email@example.com
Now copy this entire thing into clipboard. Again SSH into the server (with password). In the server, open
nano text editor and paste it as follows.
$ nano ~/.ssh/authorized_keys
This simply tells the server to accept connections from the given public key. Do the same steps for all accessing computers you plan to use. Add the entries in a new line and you are good to go.
Now if you try
ssh NAME you’ll directly land in your server’s terminal without having to type anything more. Pretty convenient!
Accessing the compute environment
Now we know how to get inside of your office or work computer. But depending on you nature of work you need to have different kinds of access. For me, as a programmer/researcher I want myself to be able to program on Visual Studio Code and Jupyter Notebook.
Accessing Jupyter Notebook
- First we start by SSH’ing into the server
- Now we start the Jupyter Notebook using
jupyter notebook --no-browsercommand. We add the flag since we are not using the browser in office.
We can see that the jupyter is running inside the other computer in port 8888. We do not have access to port 8888 and arbitrary port access is always blocked in work-place VPNs for security. But we can use SSH to access other computers’ ports. This is called port forwarding.
- SSH port forwarding.
Open a new terminal from your computer and type the following command.
$ ssh -L localhost:8888:localhost:8888 NAME
NAME is the server name you gave in previous settings. This is us simply asking SSH program to divert server’s port 8888 to our computer’s port 8888. All the data are transferred via SSH using port 22. Head to
http://localhost:8888/ to access this.
Now open the browser and use Jupyter as usual! Anywhere you like!
Accessing Visual Studio Code
It is very easy if you have all the codes at once place (backed up in a git repo of course). Imagine you being able to write code on office computer itself without having to roundtrip accross a version control system. That’s exactly what I’ll be telling you here.
Without second thoughts head to https://github.com/cdr/code-server!
While you’re in the terminal of office computer via SSH clone the repo and install. All the instructions are available in Github, and are as follows;
$ git clone https://github.com/cdr/code-server.git $ cd code-server $ sh install.sh
You might be asked to enter the password for sudo commands in the install script. Do so if asked. Now navigate to your project folder and enter
code-server. A Visual Studio web server will be started in that particular location.
Now the Visual Studio Code is running in Server’s post 8080. Simply port forward this to your computer’s port 8080 using previous instructions. Now you have a VSCode instance from your browser. Head to
http://localhost:8080/ to access this.
I do not plan to cover, yet I’ll mention few more things you can do.
- Mount the file system itself using SSHFS.
- Forward other ports such as RDP.
I’ll leave this to reader to search. They can be not so simple too!
Hope you enjoyed reading this article.
Stay safe and happy working-from-home. 🙂