May
12
sshfs and remote php debugging
May 12, 2010 | Leave a Comment
Sshfs is used for viewing and exploring remote file system as if it was your local machine. It is pretty simple to setup
#yum install sshfs fuse-sshfs
Once you have installed sshfs we can use it to connect to any server which allows ssh access
#mkdir /mnt/moodle_server
#sshfs user@server.com:/home/abcd/public_html/moodle /mnt/moodle_server/
Enter password and you re done.
Now lets say we want to debug this system locally so we will mount our system in the /var/www/html so that our apache can read it
#sshfs user@server.com:/home/abcd/public_html/moodle /var/www/html/moodle_server
I got permission denied forbidden errot. To resolve this I have it the necessary permission
#sshfs -o allow_other,uid=500;gid=500 user@server.com:/home/abcd/public_html/moodle /var/www/html/moodle_server
Bingo It lets me get in. Now only one thing remains. I need to setup the mysql user and password same as on the server locally.
Ka Ching!!!
There you go
debugging your remote file system php files right from your desktop. No upload download permision abcd stuff
If you want to auto mount the system when you access it. install a key pair using ssh-keygen. or use autofs for automounting
Want to be able to use the local rights system on that folder? (just if you dont want to go on but want to be able to mount a remote filesystem and have the
local rights translated to it.)
For default permissions
#sshfs -o allow_other, default_permissions user@server.com:/home/abcd/public_html/moodle /var/www/html/moodle_server
As i want the remote directory mount automaticly (with autofs described later on)
i need a passwordless ssh login. This can be done with help of generating public keys.
A public key for the local system is generated with the command:
ssh-keygen -t rsa
(hit enter so its saved in your home directory under .ssh/id_rsa
(hit enter for no passphrase)
you have now a .ssh directory with two files
id_rsa and id_rsa.pub
id_rsa is your private key ! protect it well let only YOU have rights on it (default) as if this gets compromised
anyone can gain access to your remote host
id_rsa.pub is the public key it is readable by others and this is what you have to send to the remote host so it can have it in its authorized_keys file
Copy now the public key to the remote machine
scp ~/.ssh/id_rsa.pub user@server.com:~/.
logon with an ssh client to the remote machine the id_rsa.pub file content must be added to the authorized_keys file in the .ssh directory of the homedir of the user you want to connect as.
In this example the remote users home directory
ssh user@server.com cat ~/id_*.pub >> ~/.ssh/authorized_keys
A alternative simpler way to get your public key in the authorized_keys file of your remote host is with ssh-copy-id
from your local machine type
ssh-copy-id -i ~/.ssh/id_rsa.pub user@server.com
this does the whole process of copying your public key to the remote machnes users homedir in .ssh in authorized_keys
and sets the rights oke
As later on the mount is done by the local root user you need the public key of root too.
so give command
sudo gnome-terminal
to open a command terminal as user root and repeat the above procedure.
after this the file authorized_keys at the remote station has both the public key of the local user and the local root so it works in test and in production later when root does the mounwork….
Set the right rights for the file authorized_keys or the ssh deamon ( in my case dropbear) might not want to process the authorize_keys file
ssh remoteuser@remote.machine.address chmod 0600 ~/.ssh/authorized_keys
logout from the remote machine and test.
ssh user@server.com
You should now be able to login without giving a password.
If it does not work debug with ssh -v option .
(same for the sudo gnome-terminal )
If it works you can see if the mount works passwordless too
sudo sshfs user@server:/Directory/to/mount /var/www/html/moodle_server
So ! thats done!!! you can now mount the remote filesystem without using a password.
Cheers!!
sshfs -o allow_other,uid=500,gid=500
academy@uspja.com:/home/academy/public_html /var/www/html/uspja_academy_server/