Jump to content

Mount website as folder with SSH

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
This will be a small tutorial to show you how you can mount a website using the SSH protocol as a folder on your harddrive you can freely modify as if it were on your own computer.

The reasoning behind this is the transparent access to the files on another host, using your own window manager or programs that need to rely on them.

First you will need to install sshfs, this command is for Ubuntu:
sudo apt-get install sshfs
With that installed you can go ahead and create a mount folder, here we are not running in root so we will be mounting in a home folder, feel free to create it in /mnt/:
mkdir ~/mount/mysite.com
From there we will mount the folder:
sshfs -p 22 user@mysite.com:/srv/www/htdocs ~/mount/mysite.com
Notice how we can modify the port with the -p switch in case you have configured SSH to run on a separate port.

That is all. Try going to /home/username/mount/mysite.com" and you will notice it is mirrored to your website directory, you can freely modify the files directly with any program or method you wish.

Note: To unmount the folder, ensure you kill all processes that are using the mounted folder (lsof can be helpful), and run the command fusermount -u:
fusermount -u $HOME/mount/mysite.com

Edited by Alexander, 19 February 2011 - 10:12 PM.

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#2
Fighter

Fighter

    Newbie

  • Members
  • PipPip
  • 28 posts
So this allows me to type something like this?
cp index.php /mnt/mysite.com/index.php

That is a very useful utility, an old host of mine supported a service like this for Windows, this could be useful for transparent access when required, I usually have a very limited set of software (no sftp client when I need ssh file access)

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
I am glad you found it useful! It can add unique way to access remote files.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users