Jeff Rhoades
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Setting up remote coding for Harvard HMS O2 and HTEM nodes (non-GUI) We will be running VS Code locally and using SSH under the hood to connect to a VS Code instance running remotely. This gives us access to data and compute resources on the remote server, while giving us a fully featured coding environment. ![](https://i.imgur.com/9dDJIQi.png) ### 1. Download, install, and setup the [Harvard HMS Virtual Private Network](https://it.hms.harvard.edu/our-services/network-and-servers/vpn). You should connect to `https://secure.med.harvard.edu/` for the VPN. ### 2. Connect to the VPN (unless you are on HMS WiFi) to make sure it works. ### 3. Install a supported SSH client as specified [here](https://code.visualstudio.com/docs/remote/troubleshooting#_installing-a-supported-ssh-client). ### 4. Create an SSH Key pair and add the Public Key to your Remote Server Open a local terminal and run `ssh-keygen -t rsa` When prompted enter a blank passphrase (just hit Enter). Then run the following, replacing `user` and `hostname` with your username on the remote server, and the path to the server (such as `catmaid2.hms.harvard.edu` or `10.117.28.249`): `cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'` You should be prompted for your server password. Try sshing in to verify it works, using the following command (replacing `user` and `hostname`): `ssh user@hostname` ### 5. Download and install [Microsoft Visual Studio Code (VS Code)](https://code.visualstudio.com/) on your local computer. ### 6. Install the [Remote Development Extension Pack for VS Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack). ### 7. Connect to a remote VS Code session In VS Code with the Remote Development Extension Pack installed, you will see a new Status bar item at the bottom far left of the window (the `><` looking button). Clicking on the item will bring up the Remote - SSH commands. Click `Remote-SSH: Connect to Host...` ![](https://i.imgur.com/jR9SjFo.png) Fill in `user@hostname` using your username and the server path, as in step #4, and hit Enter. It may take a little bit to connect, especially the first time. But then you will have all the functionality of VS Code, such as terminal, AI-assisted coding environment, live python scripts, built in Jupyter notebook, virtual environment management, and Source Control (i.e. Git/GitHub), assuming you have the necessary extensions installed ;) Once you've connected to a server once, you should be able to connect again by selecting it from the Remote Explorer tab: ![](https://i.imgur.com/d3oMbT4.gif) --- # Level 2: Control your environment For those not well acquianted with managing virtual python environments, we'll do a quick demo of using Anaconda (or Miniconda actually) to make and maintain a coding environment for us. *All of this should be done in a terminal session on the remote server.* ### 1. Make sure Anaconda/Miniconda is installed. See if `conda` is already installed by running `conda` in the terminal and seeing if it gives you an error or explains the command. If it explains the command, it is installed - continue to step #2. #### If it is not already installed, then: Change to the tmp directory then download the installer by running ``` cd /tmp wget <url> ``` Where `<url>` should be replaced with the link to the correct installer for your server found [here](https://docs.conda.io/en/latest/miniconda.html#latest-miniconda-installer-links). Most likely this will be the *Linux 64-bit* version, and you can find additional instructions [here](https://conda.io/projects/conda/en/stable/user-guide/install/linux.html). ![](https://i.imgur.com/7FlmYor.jpg) It is recommended that you [verify the download](https://conda.io/projects/conda/en/stable/user-guide/install/download.html#hash-verification) before running the installer. For Linux this would consist of running `sha256sum <filename>` where `<filename>` is the path to the downloaded install script (example: `Miniconda3-latest-Linux-x86_64.sh`). Then run `bash <filename>` and follow the prompts, choosing the default options (you can change them later). To make the changes take effect, close and then re-open your terminal window. Test your installation by running `conda list` in a new terminal window. If a list of installed packages appears it has been installed correctly. ### 2. Create your environment. Pick an appropriate or otherwise useful name for your environment. We'll call ours *next_level* because fun is important for morale. Replacing *next_level* with your name of choice, run the following: `conda create -n next_level python=3.9` This creates a new environment called *next_level* using *python 3.9*. This tends to be a pretty safe choice in terms of compatability, but feel free to replace with older or newer versions as you need. ### 3. Activate your environment. `conda activate next_level` ### 4. Control your environment. Let's install some example packages with `pip`: `pip install numpy pandas networkx python-catmaid navis` Basically add any packages available on [pypi.org](https://pypi.org/) that you would like to install. Additionally, you can add pip-installable GitHub repos with `git+<git-url>`. For instance, to install the full-refactor branch of raygun, run: `pip install git+https://github.com/htem/raygun@full_refactor` If you need to install new dependencies that would conflict with your current environment, simply deactivate it (`conda deactivate`) and repeat from step #2. --- # Level 3: Remote Python Coding with VS Code Interactive Windows in Conda Environments Now we'll put things together and do some simple coding. We'll save true 'development' including version control (via GitHub) for the next 'Next Level' ;) ### 1. [Connect to a VSCode remote session.](https://hackmd.io/_D-Pb2umR52LQ2oIfhLT1Q?both#7-Connect-to-a-remote-VS-Code-session) ### 2. Select and activate an environment. By default, the Python extension looks for and uses the first Python interpreter it finds in the system path. To select a specific environment, use the Python: Select Interpreter command from the Command Palette (`Ctrl+Shift+P`). ![](https://i.imgur.com/ARuHTht.png) The Python: Select Interpreter command displays [a list of available global environments, conda environments, and virtual environments](https://code.visualstudio.com/docs/python/environments#_where-the-extension-looks-for-environments). Pick the one [you made](https://hackmd.io/_D-Pb2umR52LQ2oIfhLT1Q?both#Next-steps-Control-your-environment). ![](https://i.imgur.com/nwt0sdB.png) The selected interpreter version will show on the right side of the Status Bar. ![](https://i.imgur.com/0KpDv5K.png) The Status Bar also reflects when no interpreter is selected. ![](https://i.imgur.com/Y3mmVXp.png) In either case, clicking this area of the Status Bar is a convenient shortcut for the Python: Select Interpreter command. *Why do we do this?* The Python extension uses the selected environment for running Python code, providing language services (auto-complete, syntax checking, linting, formatting, etc.) when you have a .py file open in the editor, opening a terminal, and, if we're lucky, running [Interactive Windows](https://code.visualstudio.com/docs/python/jupyter-support-py). ### 3. Code in an Python Interactive Window. The Python Interactive window can be used as a standalone console with arbitrary code run using the interpreter and virtual environment of your choice. To use the window as a console, open it with the Jupyter: Create Interactive Window command from the Command Palette (`Ctrl+Shift+P`). You can then type in code, using Enter to go to a new line and Shift+Enter to run the code. ![](https://i.imgur.com/tTSPewx.gif) To change the environment you're coding in, simply click the Kernel selector in the upper right corner of the Interactive Window: ![](https://i.imgur.com/poOcr3j.jpg) If you make something you're pleased with, make sure you save it, or are developing as we will discuss in the next section. ![](https://i.imgur.com/0a4jrbG.jpg) --- # Level 4: Remote Development with all of the above + Version Control (GitHub) This section will get you to a place where you should be able to comfortably develop python code remotely, saving different versions as you go to GitHub for safekeeping. We will use everything in the past sections + GitHub. Proper package development will be dealt with in the next 'Next Level' ;) ### 1. Setup your [GitHub](https://github.com) account. If you haven't already, sign up for an account at [github.com](https://github.com). I strongly recommend using a '.edu' email address if you have it, as it makes it easier to get certain perks targeted at students and the academic research community. I also recommend [configuring 'settings sync' for VSCode by logging in with your GitHub account](https://code.visualstudio.com/docs/editor/settings-sync). ### 2. Setup a new repository. While we're at github.com, let's go ahead and setup a new repository. In the upper-right corner of any page, use the drop-down menu, and select New repository. ![](https://i.imgur.com/hbAdRIF.png) Type a short, memorable name for your repository. For example, "hello-world". ![](https://i.imgur.com/li5NRZj.png) Optionally, add a description of your repository. [Choose a repository visibility](https://docs.github.com/en/repositories/creating-and-managing-repositories/about-repositories#about-repository-visibility). ![](https://i.imgur.com/4VpLbtl.png) Select Initialize this repository with a README. ![](https://i.imgur.com/8DSBL1z.png) Click Create repository. ![](https://i.imgur.com/FldEhoP.png) ### 3. [Connect to a VS Code remote session.](https://hackmd.io/_D-Pb2umR52LQ2oIfhLT1Q?both#7-Connect-to-a-remote-VS-Code-session) ### 4. [Connect VS Code and GitHub](https://code.visualstudio.com/docs/sourcecontrol/github). First, install the [GitHub Pull Requests and Issues extension](vscode:extension/GitHub.vscode-pull-request-github). Once you've installed the GitHub Pull Requests and Issues extension, you'll need to sign in. Follow the prompts to authenticate with GitHub in the browser and return to VS Code. ![](https://i.imgur.com/bPgVw0J.png) *If you are not redirected to VS Code, you can add your authorization token manually. In the browser window, you will receive your authorization token. Copy the token, and switch back to VS Code. Select Signing in to github.com... in the Status bar, paste the token, and hit Enter.* [Generate an SSH key, add it to the ssh-agent](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) and [add it to your GitHub](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account). *NOTE*: Should you run into mysterious trouble pushing updates to the remote repo, make sure your [local repo is setup to use SSH instead of HTTPS authentification](https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories#switching-remote-urls-from-https-to-ssh) (Comment if this was confusing and I should expand the details here :) ### 5. Clone the repo you made in step 2. Run the following in a terminal, replacing `<username>` with your GitHub username and `<repository name>` with the name of your repository. Do this in the directory where you wish the repo to reside. `git clone git@github.com:<username>/<repository name>.git` Open the folder containing the repo in the File Explorer (icon on the top left). #### Alternatively: You can search for and clone a repository from GitHub using the Git: Clone command in the Command Palette (`Ctrl+Shift+P`) or by using the Clone Repository button in the Source Control view (available when you have no folder open). ![](https://i.imgur.com/4k00z3b.png) From the GitHub repository dropdown you can filter and pick the repository you want to clone locally. ![](https://i.imgur.com/jPPS0DA.png) You will likely be prompted to authenticate with GitHub. ![](https://i.imgur.com/yMz5hej.png) Follow the steps to sign in or, if you run into trouble, try consulting [the GitHub page about authentification](https://docs.github.com/en/github/authenticating-to-github/about-authentication-to-github). ### 6. Develop. Start a new python file (e.g. `hello.py`) and add `#%%` as the first line. After this, you will be able to run code blocks (delineated by `#%%`'s) by hitting Ctrl+Enter. They will automatically be run in a new Interactive Python Window, as we used in the last level. Between the interactive window, saving to your python file, and committing changes to GitHub, you now have a fully fledged remote development environment. Congratulations! ![](https://i.imgur.com/gA7rmLm.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully