There might be a need for you to mount remote filesystem from another linux box, in my case I was doing cross compile packages and stuff from my remote linux server. It would take less time if I can mount this remote machine to my router so I don’t have to download and transfer or tar and untar the files.
I was doing this on TP-LINK MR3020 with extroot and with firmware OpenWrt Attitude Adjustment 12.09 . Make sure you have enough spaces to install the sshfs and its dependencies.
SSH to router and install sshfs
1 2 3 |
opkg update opkg install sshfs reboot |
If you enable the remote SSH for password authentication then the process of mounting will be straight forward, just run the command “sshfs @: ”
1 2 |
mkdir /mnt/openwrt sshfs -o reconnect,compression=yes mahadir@192.168.1.122:/home/mahadir /mnt/openwrt/ |
For public/private key authentication you have to generate using dropbear or use dropbearconvert for converting from OpenSSH private key. I would prefer to generate new dropbear for simplicity.
Generate dropbear RSA private key and save to private_rsa
1 2 |
cd /root dropbearkey -t rsa -f private_rsa.key -s 2048 |
You would see output similar to this
Will output 2048 bit rsa secret key to ‘private_rsa’
Generating key, this may take a while…
Public key portion is:
1 |
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAwCoOtM/ItDGWfq0QAgrm6IeyZsDBrZIhYoto8WPOLwR4v4VDaqUZ6Eo47VtHrRK0IxlqpXNQxYugzZFqICD5vyh5BlcKaPt9h2oV7VWtWgcZT4GM0XsVvgee3i8swU48rw1MEas0Tr6vgGGXsVSuJqjLStOHIvz19EwUaLH3BOFifPFTMsUs7YBew6ahbQcowDWyIjiuhdS4GrgzMrD4wuCFzrk5OC67qEUzW2Zfjb3ceB9rPIoBDFcpVEjH1t1cZeUjX/Dr4bS/R1bN5/jH1EnkVTuXZwIoWeWpFjdHoUyPrng9zTGMTtiqQYZo0S17RhhagK7/tYdwPfEUOyfNdav040= root@tlmr3020.madet.my |
Copy the portion of the public key, which start with ssh-rsa until end of the line and paste to your authorized_keys on remote machine.
1 2 3 4 5 6 |
mkdir .ssh chmod 700 .ssh cd .ssh touch authorized_keys chmod 600 authorized_keys vim authorized_keys |
Run sshfs with the private key on your router.
1 |
sshfs -o reconnect,compression=yes,ssh_command="ssh -p 22 -i /root/private_rsa.key" mahadir@192.168.1.122:/home/mahadir /mnt/openwrt/ |