How to map local directory to remote directory
Operate on a remote server through terminal is tedious. I am going to show you how to map local directory to remote directory, so you could easily operate changes on server in your computer.
I am going to demonstrate step-by-step the mapping process on macOS.
Step 1. Install required packages
- Install Homebrew if you don’t have one. Type this on terminal.
(bash) >>> /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Install osxfuse
(bash) >>> brew install Caskroom/cask/osxfuse
- Install sshfs
(bash) >>> brew install sshfs
Step 2. Construct ssh connection.
(bash) >>> cd ~/.ssh # Go to .ssh folder
(bash) >>> vim id_rsa.pub # open id_rsa.pub file
Copy the the public key and upload it on the server to get ssh permission access.
Step 3. Construct mapping
Choose an empty folder in your computer and map it to the remote server.
(bash) >>> touch /local/directory
(bash) >>> sshfs -C -o reconnect user@hostname:remote_dir local_dirFor example:
(bash) >>> sshfs -C -o reconnect work@12.34.56.789:/remote/directory /local/directory
That’s it! You’ll see the icon of the folder change on macOS.
Step 4. Shut down mapping
Check the running sshfs and copy the mapping directory in your computer.
(bash) >>> pgrep -lf sshfs
Unmount the connection.
(bash) >>> umount -f /local/directory
Happy mapping :)