Skip to content

Instantly share code, notes, and snippets.

@ickc
Last active December 20, 2023 23:47
Show Gist options
  • Save ickc/958b0d4e4642395ab0272a43f6388a2c to your computer and use it in GitHub Desktop.
Save ickc/958b0d4e4642395ab0272a43f6388a2c to your computer and use it in GitHub Desktop.
Using mosh at NERSC

Mosh is a replacement for interactive SSH terminals. It's more robust and responsive, especially over Wi-Fi, cellular, and long-distance links. from Mosh: the mobile shell

Preparation

mosh-server

You need your host to have mosh-server. So you need to

  1. install it
  2. made it discoverable at login stage

Installing on NERSC is slightly complicated. Options:

  1. At NERSC you can use put this in your .bash_profile/.bashrc/.zshenv if you have access to polar:

    alias mosh-server=/global/common/software/polar/.conda/envs/system39-conda-forge/bin/mosh-server

  2. else the easiest way to install mosh at NERSC is through conda. Create your own conda virtual environment, install mosh, find out its path by which mosh-server, make an alias like above and you're done.

  3. Another easy way is use homebrew (formerly linuxbrew). But I haven't tried it in a while as I experienced some problem after linuxbrew is merged back to homebrew.

mosh-client

And you can obtain mosh-client by installing mosh from your typical package manager.

Connecting to NERSC

  1. Using sshproxy for NERSC to obtain the ssh cert. first by sshproxy.sh -u NERSC_USERNAME
  2. (optional) ssh to NERSC normally, the login server will load balance you to an actual node. Say cori11.
  3. Connect to cori11-224.nersc.gov using mosh, by replacing ssh by mosh.
  4. If you cannot connect by now,
    • probably you need to file a NERSC ticket for approval. I have special approval from NERSC staff before I can use it years ago, if you cannot connect mosh, then you can open a NERSC ticket and ask for approval. It is because the libopenssl and possibly protobufs are "instrumented" at NERSC. They said they would approve me for experiment and continue to monitor my account and so far there's no security issue. See Instrumented SSH on NERSC Systems, mobile-shell/mosh#941 (comment)
    • it may not discover mosh-server, alias explicitly as above can solve this

Tips

In ~/.ssh/config, add

Host cori
    HostName %h.nersc.gov
    User NERSC_USERNAME
    IdentityFile ~/.ssh/nersc

Host cori??
    HostName %h-224.nersc.gov
    User NERSC_USERNAME
    IdentityFile ~/.ssh/nersc

Then you can login to NERSC in a one-liner:

sshproxy.sh -u NERSC_USERNAME; mosh $(ssh cori hostname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment