To have O2 accessible on your laptop/desktop as a folder, you need to use something called sshfs (ssh filesystem). This is a command that is not native to OSXand you need to go through several steps in order to get it. Once you have sshfs, then you need to set up ssh keys to connect O2 to your laptop without having to type in a password.
Download macFUSE from https://github.com/osxfuse/osxfuse/releases, and install it.
NOTE: In order to install macFUSE, you may need to first enable system extensions, following this guideline from Apple, which will require restarting your computer.
Download sshfs from https://github.com/osxfuse/sshfs/releases, and install it.
Step 1. Install Xcode
$ xcode-select --installStep 2. Install Homebrew using ruby (from Xcode)
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # Uninstall Homebrew # /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"Step 2.1. Check to make sure that Homebrew is working properly
$ brew doctorStep 3. Install Cask from Homebrew's caskroom
$ brew tap caskroom/caskStep 4. Install OSXfuse using Cask
$ brew cask install osxfuseStep 5. Install sshfs from fuse
$ brew install sshfs
Once sshfs is installed, the next step is to connect O2 (or a remote server) to our laptops. To make this process seamless, first set up ssh keys which can be used to connect to the server without having to type in a password every time.
Log into O2 and use vim to open ~/.ssh/authorized_keys and paste the code below copied from your computer to this file and save it. NOTE: make sure to replace ecommonsID with your actual username!
# set up ssh keys
$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -C "ecommonsID"
$ ssh-add -K ~/.ssh/id_rsaArguments for ssh-keygen:
-t= Specifies the type of key to create. The possible values are "rsa1" for protocol version 1 and "rsa" or "dsa" for protocol version 2. We want rsa.-b= Specifies the number of bits in the key to create. For RSA keys, the minimum size is 768 bits and the default is 2048 bits. We want 4096-f= name of output "keyfile"-C= Provides a new comment
Arguments for ssh-add:
-K= Store passphrases in your keychain
# copy the contents of `id_rsa.pub` to ~/.ssh/authorized_keys on O2
$ cat ~/.ssh/id_rsa.pub | pbcopy
pbcopyputs the output ofcatinto the clipboard (in other words, it is equivalent to copying with ctrl + c) so you can just paste it as usual with ctrl + v.
Now, let's set up for running sshfs on our laptops (local machines), by creating a folder with an intuitive name for your home directory on the cluster to be mounted in.
$ mkdir ~/O2_mountFinally, let's run the sshfs command to have O2 mount as a folder in the above space. Again, replace ecommonsID with your username.
$ sshfs ecommonsID@transfer.rc.hms.harvard.edu:. ~/O2_mount -o volname="O2" -o compression=no -o Cipher=arcfour -o follow_symlinksNow we can browse through our home directory on O2 as though it was a folder on our laptop.
If you want to access your lab's directory in
/groups/or your directory in/n/scratch2, you will need to create sym links to those in your home directory and you will be able to access those as well.
Once you are finished using O2 in its mounted form, you can cancel the connection using umount and the name of the folder.
$ umount ~/O2_mount It is optional to set shorter commands using alias for establishing and canceling sshfs connection. Use vim to create or open ~/.bashrc and paste the following alias commands and save it.
$ alias mounto2='sshfs ecommonsID@transfer.rc.hms.harvard.edu:. ~/O2_mount -o volname="O2" -o follow_symlinks'
$ alias umounto2='umount ~/O2_mount'If your default shell is
zshinstead ofbash, usevimto create or open~/.zshrcand paste thealiascommands.
Update changes in .bashrc
$ source .bashrcNow we can type mounto2 and umounto2 to mount and unmount O2.
This lesson has been developed by members of the teaching team at the Harvard Chan Bioinformatics Core (HBC). These are open access materials distributed under the terms of the Creative Commons Attribution license (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.