sshsf + Macfuse
sshsf
https://github.com/libfuse/sshfs
https://eud.gsfc.nasa.gov/David.Friedlander/my_docs/fuse_for_macs.html
https://sbgrid.org/corewiki/faq-sshfs.md
https://sbgrid.org/corewiki/faq-sshfs.md
https://sbgrid.org/corewiki/faq-sshfs.md
Setting up sshfs on OS X (Mac) systems
Installation requires administrative privileges.
Prior to installing, you should make sure that you can SSH with keys
- Download OSXFuse (
dmg
) (pkg
) from http://osxfuse.github.io
- Open OSXFuse
dmg
, run installer
- Download SSHFS (
pkg
) from from http://osxfuse.github.io
- Run SSHFS installer
pkg
- Create a folder to access the remote filesystems (aka a mount point):
mkdir /sshfs/
Mounting remote filesystems with sshfs
sshfs username@remotesystem:/full/path/to/directory /mount/point
For example, sshfs meyer@schl15:/nfs/userdocs/ps/meyer ~/userdocs/home
would use schl15
as a host to access the directory /nfs/userdocs/ps/meyer
(in other words, that user's NFS home directory).
You should mount sshfs via a directory in your home directory. Just remember to specify the PATH to the directory.
OS X (Mac) helpful hints
As of OSX 10.15 Catilina we are not recommending to create mounts in the root path or / of the file system.
An example of mounting from OSX on your local system is as follows –
mkdir ~/userdocs
/usr/local/bin/sshfs oconnor@xtal200.harvard.edu:/nfs/userdocs /Users/oconnor/userdocs -o volname=userdocs,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,idmap=user,auto_xattr,dev,suid,defer_permissions,noappledouble,noapplexattr
You should mount one complete filesystem from the remote site, so this would be anything listed in /nfs for example. This avoids local Apple Finder issues. We give the volume a name volname=userdocs
(shows mount point on your desktop), add some additional options for server connections, etc. If you are using an key-based-ssh you would add it's path to the IdentityFile paramater – adding ,IdentityFile=$HOME/.ssh/id_rsa
to the end of the line.
Unmounting remote filesystems
On occasion the mount may become stuck or unresponsive you can force unmount via – diskutil umount force /Users/oconnor/userdocs
Using helper script
We created a 'helper' script available that can be used with sshfs_nfs.app for mac to automount at login. The app is simply a wrapper for sshfs-helper.sh and assumes the script exists in your home folder.
If the mounts become stuck just rerun to reattach shares.
scp $USER@xtal200.harvard.edu:/net/cronus/cmcd1/arc/shared/sshfs-helper.sh .
or copy the whole set –
rsync -rlptD $USER@xtal200.harvard.edu:/net/cronus/cmcd1/arc/shared/sbgrid-sshfsfiles.zip .
The script will create a file in your home folder called .sshfs-mounts
You can add or change any number of mounts that sshfs-helper.sh –
To open – open .sshfs_mounts
then edit in textedit.app.
An example – #USER@HOST REMOTE_FOLDER LOCAL_FOLDER | empty local folder must exist
oconnor@sshfs.sbgrid.org /nfs/userdocs /Users/oconnor/userdocs
jo232@transfer.o2.hms.harvard.edu /home/myfolder /Users/oconnor/o2home
After it is working you can add a shortcut into your dock by navigating to your home folder on your Mac open ~
and then dragging the sshfs_nfs.app into your dock. If you need to reconnect to the shares just press the app and it will connect or reconnect. For additional folders you must create the destination folder like – mkdir ~/o2home
After it is working you can add a shortcut into your dock by navigating to /Users/Shared/ on your Mac open /Users/Shared
and then dragging the sshfs_nfs.app into your dock. If you need to reconnect to the shares just press the app and it will connect or reconnect.
May have to ssh into bluehost first – then connect via sshsf
sshfs username@hostname:/remote/directory/path /local/mount/point
sshfs username@xxx.xxx.xxx.x:/home3/xxxxxx/public_html/ ~/desktop/sshsf/bluehost -o reconnect,idmap=user,password_stdin,dev,suid
alias sshfs_bluehost ‘sshfs username@xxx.xxx.xxx.x:/home3/xxxxxx/public_html/ ~/desktop/sshsf/bluehost -o reconnect,idmap=user,password_stdin,dev,suid’
In this command, /remote/directory/path is the path to the desired folder on the remote server that you have access to. (Alternatively, you can just use a forward slash to mount the root directory.) The /local/mount/point is the full path on your current system to the new mount folder. For example, if you want to mount the entire root file system from the remote computer at a folder called “mount” in your home directory, then you would run a command similar to the following:
sshfs username@hostname:/ ~/mount
shortcut
tcsh version:
alias my_econ ‘sshfs bobama@westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount’
re-connect option
You can run sshfs with the “reconnect” option. We use sshfs with PAM/automount to share server files for each workstation in our network. We use -o reconnect as parameter for sshfs, mostly because our users suspended their computers and on wake sshfs would not reconnect (or respond, or anything).
For example:
sshfs mvaldez@192.168.128.1:/home/mvaldez/REMOTE /home/mvaldez/RemoteDocs -o reconnect,idmap=user,password_stdin,dev,suid
Just a note, if the remote computer is really down, sshfs may become unresponsive for a long time.
HOW TO MOUNT DISKS WITH SSHFS
Create a mount point. (Either do this once in a permanent location or create something under /tmp.)
mkdir $HOME/my_remote_mount
The name can be anything you want, but don’t have spaces in the name.
Simple version of the mount:
sshfs remote_username@remote_host:/path/to/desired/dir $HOME/my_remote_mount
e.g.,
sshfs bobama@westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount
If your username is the same locally and remotely, you can omit it, as you would for plain ssh:
sshfs westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount
HOW TO UNMOUNT DISKS
The man page for sshfs says to use fusermount -u usermount. This doesn’t work for Macs because the fusermount command does not exist! Fortunately, there are various easy ways to unmount the disk:
From the command line:
umount /path/to/mount/point
e.g.,
umount $HOME/my_remote_mount
From the Finder, drag the remote disk to the Trash
From the Finder, right-click (or control-click) on the remote disk and Eject.
CREATE ALIASES TO EASE FUTURE USE
Once you have your sshfs setup the way you like it, it is highly recommended to capture that into an alias that you place in your .cshrc or .bash_profile startup file. It could be something like this:
tcsh version:
alias my_econ ‘sshfs bobama@westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount’
bash version:
alias my_econ=’sshfs bobama@westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount’
https://www.digitalocean.com/community/tutorials/how-to-use-sshfs-to-mount-remote-file-systems-over-ssh
How To Use SSHFS to Mount Remote File Systems Over SSH
Linux Basics
Introduction
In many cases it can become cumbersome to transfer files to and from a droplet. Imagine a development usage scenario where you are coding apps remotely and find yourself uploading a script repeatedly to your virtual server to test. This can become quite a hassle in a very short period of time. Luckily there is a way to mount your VPS file system to your local computer so you can make changes on the fly and treat your droplet as local storage. In this article, we will show you how to do exactly that.
Installing SSHFS
On Ubuntu/Debian
SSHFS is Linux based software that needs to be installed on your local computer. On Ubuntu and Debian based systems it can be installed through apt-get.
sudo apt-get install sshfs
On Mac OSX
You can install SSHFS on Mac OSX. You will need to download FUSE and SSHFS from the osxfuse site
On Windows
To install SSHFS in Windows you will need to grab the latest win-sshfs package from the google code repository. A direct download link can be found below. After you have downloaded the package, double click to launch the installer. You may be prompted to download additional files, if so the installer will download the .NET Framework 4.0 and install it for you.
https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/win-sshfs/win-sshfs-0.0.1.5-setup.exe
Mounting the Remote File System
The following instructions will work for both Ubuntu/Debian and OSX. Instructions for Windows systems can be found at the bottom of the tutorial.
To start we will need to create a local directory in which to mount the droplet’s file system.
sudo mkdir /mnt/droplet <--replace "droplet" whatever you prefer
Now we can use sshfs to mount the file system locally with the following command. If your VPS was created with a password login the following command will do the trick. You will be asked for your virtual server’s root password during this step.
sudo sshfs -o allow_other,default_permissions root@xxx.xxx.xxx.xxx:/ /mnt/droplet
If your droplet is configured for login via ssh key authorization, you will need to tell sshfs to use your public keys with the following command. You will be asked to enter the passphrase you used during the creation of your keys with ssh-keygen.
sudo sshfs -o allow_other,default_permissions,IdentityFile=~/.ssh/id_rsa root@xxx.xxx.xxx.xxx:/ /mnt/droplet
In case that you don’t have your SSH key stored under the root user, you would need to specify the full path to the private SSH key as follows:
sudo sshfs -o allow_other,default_permissions,IdentityFile=/home/your_user/.ssh/id_rsa root@xxx.xxx.xxx.xxx:/ /mnt/droplet
Make sure to change the your_user part with your actual user.
Now you can work with files on your droplet as if it were a physical device attached to your local machine. For instance, if you move to the /mnt/droplet directory on your local machine you can create a file locally and the file will appear on your virtual server. Likewise, you can copy files into the /mnt/droplet folder and they will be uploaded to your droplet in the background.
It is important to note that this process provides only a temporary mount point to your droplet. If the virtual server or local machine is powered off or restarted, you will need to use the same process to mount it again.
Unmounting the Remote File System
When you no longer need the mount point you can simply unmount it with the command
sudo umount /mnt/droplet
Permanently Mounting the Remote File System
SSHFS also allows for setting up permanent mount points to remote file systems. This would set a mount point that would persist through restarts of both your local machine and droplets. In order to set up a permanent mount point, we will need to edit the /etc/fstab
file on the local machine to automatically mount the file system each time the system is booted.
First we need to edit the /etc/fstab
file with a text editor.
sudo nano /etc/fstab
Scroll to the bottom of the file and add the following entry
sshfs#root@xxx.xxx.xxx.xxx:/ /mnt/droplet
Save the changes to /etc/fstab
and reboot if necessary.
It should be noted that permanently mounting your VPS file system locally is a potential security risk. If your local machine is compromised it allows for a direct route to your droplet. Therefore it is not recommended to setup permanent mounts on production servers.
Using Win-SSHFS to Mount Remote File Systems on Windows
After launching the win-sshfs program, you will be presented with a graphical interface to make the process of mounting a remote file share simple.
- Step 1: Click the Add button in the lower left corner of the window.
- Step 2: Enter a name for the file share in the Drive Name field.
- Step 3. Enter the IP of your droplet in the Host field.
- Step 4. Enter your SSH port. (Leave as port 22 unless you have changed the SSH port manually).
- Step 5. Enter your username in the Username field. (Unless you have set up user accounts manually you will enter
root
in this field).
- Step 6. Enter your SSH password in the password field. (Note on Windows you will need to have your droplet configured for password logins rather than ssh-key-authentication).
- Step 7. Enter your desired mount point in the Directory field. (Enter
/
to mount the file system from root. Likewise you can enter /var/www
or ~/
for your home directory).
- Step 8. Select the drive letter you would like Windows to use for your droplets file system.
- Step 9. Click the Mount button to connect to the droplet and mount the file system.
Now your virtual server’s file system will be available through My Computer as the drive letter you chose in step 8.
Usage of the Remote Mount Point
The remote mount behaves similarly to locally mounted storage: you are able to create, copy, move, edit, compress or perform any file system operations you would be able to do on the droplet, but you are not able to launch programs or scripts on the remote server.
One typical usage of this would be if you host a website on your VPS and need to make changes to the website on a regular basis. Mounting the file system locally allows you to launch whatever code editor, IDE, or text editor you wish to edit the site, and any changes you make will reflect on the virtual server as soon as they are made on your local machine.
Similarly, on droplets used for testing purposes of coding projects, it allows for much simpler code modifications which can be tested immediately without the need to modify the code locally as well as remotely (and eliminates the hassle of uploading new copies of files for small code changes).
How to mount and manage non-native file systems in OS X with FUSE
https://clickety-clack.click/img/how-to-mount-and-manage-non-native-file-systems-in-os-x-with-fuse.html
Mac OS X supports a handful of common file systems—HFS+, FAT32, and exFAT, with read-only support
for NTFS. It can do this because the file systems are supported by the OS X kernel. Formats such as Ext3 for Linux systems are not readable, and NTFS can’t be written to. But that doesn’t mean that there aren’t occasions when you’d want to use one of them. With FUSE (Filesystem in Userspace) you can.
FUSE mimics the kernel’s handling of file systems and allows OS X to both interact with unsupported formats and use many other storage routines, some of which are rather creative. With FUSE, such formats can be handled very similarly to natively supported file systems and allow you to interact with drives your Mac otherwise could not read to or write from. Here’s how you can put FUSE to work.
What is FUSE?
FUSE works by providing a behind-the-scenes interface between Apple’s storage routines and specially programmed modules that you install on your Mac. These modules can read various storage formats, and then, with FUSE’s help, can be mounted and accessed as a drive-like storage medium. For instance, if you have several cloud-based storage accounts, you can write a small module that will connect all of these services with FUSE. You can then mount them as a single volume on the system
, much like you’d plugged in a USB drive.
FUSE has its limitations, however. File system access performs less well than with native kernel support, for example. On the other hand it offers vast flexibility in storage options
. For instance, in addition to using multiple Web storage services as a single drive, FUSE modules have been written to use PNG image files for storing drive data. In this case a mounted storage device’s data will be spread out among a number of garbled PNG images (a perhaps amusing, but frankly bizarre, way to manage your files).
These approaches are experimental and fun, but FUSE does have useful options that allow you to expand your Mac’s file system support beyond the natively supported formats, including allowing access to Ext3 drives, full NTFS support, and even letting you mount SFTP shares as local drives.
To get started, download and install FUSE for OS X. Once installed, you can install the desired module for the various file systems you would like to manage on your Mac. Keep in mind that some modules are well tested and regularly used, while others might not be. And some are more integrated in OS X while others will require Terminal commands to mount their file systems.
FUSE and NTFS
For NTFS support, one of the more popular FUSE modules is NTFS-3G, an open-source package from Tuxera. To acquire it you have several options. You can download an older precompiled version of NTFS-3G. The more technically inclined can download and compile the latest source code either directly from Tuxera or by using a package manager like MacPorts or Fink.
Once installed, an attached NTFS drive should be automatically recognized and mounted using NTFS-3G and FUSE. In addition, you should be able to format drives as NTFS using Disk Utility.
With the assistance of FUSE you can format drives as NTFS using Disk Utility.
Using Ext3
For Linux Ext2 and Ext3 file systems, you can use the fuse-ext2 module, and then mount Ext2 and Ext3 drives using Terminal (automatic mounting and managing in Disk Utility
is not yet supported). Follow these steps:
1. Install the ext2 FUSE module.
Sponsored Contentby OTHER WORLD COMPUTING
OWC’s new Thunderbolt Dock showcases the power of your Thunderbolt port
2. Enable Disk Utility’s Debug menu, using the following command in Terminal, followed by opening Disk Utility and choosing the option in the Debug menu to show all partitions:
defaults write com.apple.DiskUtility DUDebugMenuEnabled 1
3. Attach your ext2/ext3 drive and when it appears in Disk Utility (grayed out), select the volume and press Command-I to produce its Information window. In this window note the device name, which should be something like “disk2s2,” or “disk3s2.”
4. Create a new folder somewhere in your user account to use as a mount point for the drive (I recommend a folder called “mount” directly in your home folder).
5. Mount the drive using the following Terminal command syntax, replacing the device name and mount path with that of your disk and the path to the mount folder you created:
fuse-ext2 /dev/disk2s2 /Volumes/mountpoint
This will mount the drive as read-only, but you can use the “-o force” flag in the following manner to implement write support:
fuse-ext2 -o force /dev/disk2s2 /Volumes/mountpoint
After performing these steps, the ext2/ext3 drive will be fully accessible from the folder you created and specified to use as the mount point.
Using SSHFS
In addition to supporting locally attached drives, FUSE can be used to access remote systems and mount their shared resources locally. Granted, you can do this with SMB and AFP protocols when you have enabled File Sharing on a remote Mac, but since enabling SSH with the Remote Login service also enables SFTP access, you can use the SSHFS module for FUSE to access your Mac’s files directly over the encrypted SFTP connection.
1. Download and install the SSHFS module (available from the FUSE for OS X page).
2. As with managing Ext2 and Ext3 drives, create a folder on your Mac to use as a mount point
3. In Terminal, run a command similar to the following to access a folder on the remote system and mount it at the folder you created:
sshfs username@hostname:/remote/directory/path /local/mount/point
In this command, /remote/directory/path
is the path to the desired folder on the remote server that you have access to. (Alternatively, you can just use a forward slash to mount the root directory.) The /local/mount/point
is the full path on your current system to the new mount folder. For example, if you want to mount the entire root file system from the remote computer at a folder called “mount” in your home directory, then you would run a command similar to the following:
sshfs username@hostname:/ ~/mount
While these approaches with FUSE can be used to mount various file system formats, for the most part, you will not need special approaches for handling hard drives and other storage media. The built-in support in OS X is enough for most uses, but there are some special cases where the storage management options offered by FUSE can be useful.
Note: When you purchase something after clicking links in our articles, we may earn a small commission. Read our for more details.
https://clickety-clack.click/img/fuse_for_macs.html
Setting up MacFUSE and sshfs (and more)
Background
The FUSE (Filesystem in USErspace) system is a method to allow secure mounting of remote disks and filesystems without requiring root privileges on either end. While it began as a kernel extension for Linux, it is now available for OS X as well. (See the Fuse4X/OSXFUSE page for more information.)
Of particular interest to us is the Secure Shell Filesystem, sshfs.
SSHFS allows you to mount a remote disk from any computer for which you otherwise have ssh shell access. (SSHFS operates as a compiled shell around SFTP.) At that point, you have local Mac access to the files on the remote server, with the same (read-write-execute) permissions you would have if you had ssh'ed to start a remote shell on that computer. However, you can bring the power of your Mac to bear on those files, including editing them with local applications (TextWrangler, TeXShop, Photoshop), inspecting them (the Finder, QuickLook), and more.
Furthermore, SSHFS can do 'tricks' that NFS (Network File System) cannot, such as (a) mounting a server disk from a wireless computer and (b) not requiring root access on either the UNIX server or the local Mac.
Installation
While there are GUI installers available for this, it is very easy to get this running via MacPorts or Fink.
If you are running 10.6 installed by the ASD system team, then you probably have Fink (unless you installed MacPorts on your own). For 10.8 systems, ASD would have provided you with MacPorts, while the 10.7 systems are a mixture (look for /sw or /opt/local for Fink or MacPorts, respectively).
- MacPorts: sudo port install sshfs
- Fink: fink install sshfs
How to mount disks with sshfs
- Create a mount point. (Either do this once in a permanent location or create something under /tmp.)
mkdir $HOME/my_remote_mount
The name can be anything you want, but don't have spaces in the name.
- Simple version of the mount:
sshfs remote_username@remote_host:/path/to/desired/dir $HOME/my_remote_mount
e.g.,
sshfs bobama@westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount
If your username is the same locally and remotely, you can omit it, as you would for plain ssh:
sshfs westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount
How to unmount disks
The man page for sshfs says to use fusermount -u usermount. This doesn't work for Macs because the fusermount command does not exist! Fortunately, there are various easy ways to unmount the disk:
- From the command line:
umount /path/to/mount/point
e.g.,
umount $HOME/my_remote_mount
- From the Finder, drag the remote disk to the Trash
- From the Finder, right-click (or control-click) on the remote disk and Eject.
Create aliases to ease future use
Once you have your sshfs setup the way you like it, it is highly recommended to capture that into an alias that you place in your .cshrc or .bash_profile startup file. It could be something like this:
tcsh version:
alias my_econ 'sshfs bobama@westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount'
bash version:
alias my_econ='sshfs bobama@westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount'
Pip – to break up code
https://www.geeksforgeeks.org/how-to-install-pip-in-macos/
Before we start with how to install pip for Python on macOS, let’s first go through the basic introduction to Python. Python is a widely-used general-purpose, high-level programming language. Python is a programming language that lets you work quickly and integrate systems more efficiently.
PIP is a package management system used to install and manage software packages/libraries written in Python. These files are stored in a large “on-line repository” termed as Python Package Index (PyPI).
pip uses PyPI as the default source for packages and their dependencies. So whenever you type:
pip install package_name
pip will look for that package on PyPI and if found, it will download and install the package on your local system.
Download and Install pip:
pip can be downloaded and installed using command-line by going through the following steps:
-
Download the
get-pip.py
file and store it in the same directory as python is installed.
or
Use the following command to download pip directly,
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
-
Now execute the downloaded file using below command
python3 get-pip.py
and wait through the installation process.
-
Voila! pip is now installed on your system.
Verification of the Installation process:
One can easily verify if the pip has been installed correctly by performing a version check on the same. Just go to the command line and execute the following command:
pip3 --version
Attention geek! Strengthen your foundations with the Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course
Splittling large xml files
Splitting XML file on Mac
To split files on your Mac, you need to use a different and simpler script written in python called ‘mainSplit’.
Now go to the intro page and at the botton of the page, download mainSplit.py script. Make sure to download the file in (.py) extension and not (.txt) extension.
Once downloaded, open Terminal console that’s available from Application > Utilities folder on your Mac and enter the following line:
python mainScript.py
Running the line will open a small window of ‘WordPress XML Splitter’. Click on button ‘Browse File’ to select the XML file you want to split, and then select the folder you want the file to be saved to by clicking on ‘Browse Dir.’
When ready, click the ‘Start’ button and the processing will start immediately.
To check the split files, go to the directory you have selected earlier, and you will see a collection of files, not more than 2Mb in size each.
Conclusion
Both solutions on Mac and Windows are pretty much similar, although you are using different programs and scripts. The process is simple and fast, making your migration process easy with WordPress. There are many other ways to backup your WordPress files, but this approach of splitting XML files manually does not take a lot of your time.
Converting XML to JSON
How to Convert XML to JSON on the Command Line
XML is complicated, and parsing it natively is fairly hard, even with scripting languages. Luckily, there’s a utility that can convert XML to JSON, which is easier to work with, both in scripts and on the command line.
Use the xq Utility
You’ll want to use a custom made utility for this, rather than trying to parse it with something like regex, which is a bad idea. There’s a utility called xq
that is perfect for this task. It’s installed alongside yq
, which works for YAML. You can install yq
from pip:
pip install yq
Under the hood, this utility uses to handle working with JSON, so you’ll need to download the binary, and move it to somewhere on your PATH (/usr/local/bin/
should work fine).
Now, you’ll be able to parse XML input by piping it into xq
:
cat xml | xq .
The .
operator means you want to convert all of the XML to JSON. You can actually use full jq
syntax here to select sub-elements, which you can read our guide on.
You can also output xq
‘s response as XML with the -x
flag:
xq -x
This lets you use jq
‘s selection syntax to parse XML while keeping it in XML form. Though it doesn’t seem to be able to convert the other way, as xq
still wants XML syntax in.
One Problem With XML to JSON Conversion
XML to JSON isn’t a perfect conversion—in XML, the order of the elements can matter, and keys can be duplicated. A document like:
<e>
<a>some</a>
<b>textual</b>
<a>content</a>
</e>
Would produce an error if translated outright to JSON, because the a
key exists twice. So, it’s converted to an array, which does break the order. xq
returns the following output for that bit of XML:
{
"e": {
"a": [
"some",
"content"
],
"b": "textual"
}
}
Which is technically correct, just not ideal in all situations. You’ll want to double-check and make sure your XML conversion has no issues.