Sometimes you need to mount a remote file system locally in order to share files, do some work or deploy a program remotelly. There are several protocols to do this like NFS, Samba, SSHFS and others. Here are some recipes.
Provided you have a user and password (or ssh keys loaded in the remote host) and an ssh server is running on the remote host, you can mount the remote filesystem through an SSH connection.
First, install sshd
:
sudo apt install sshfs
Then just create the local mount point (directory) for the remote file system and use sshfs
to mount. Given your user is myuser
in the remote host, the remote host is called remote-host
, the directory on the remote host that you want to mount is /home/myuser
and the local directory where you want to mount is ~/remote-dir
, type the following:
mkdir ~/remote-dir
sshfs myuser@remote-host:/home/myuser ~/remote-dir
That's it, but keep in mind that you'll have the same permissions of your remote user on the mounted filesystem so you can
accidentally delete things. If you want to mount read only, use the -o ro
option, like this:
sshfs myuser@remote-host:/home/myuser ~/remote-dir -o ro
You can pass several options, check the sshfs
manual for more info.
Lets say you have a binary image imgfile.img
compressed in some format (.zip, .xz, .tar.gz) and you want to write it to /dev/sdc
,
which is block device (an SD card most likely). This is how you do it in different forms, depending on the compressed file.
Use xzcat
with a pipe to dd
:
xzcat imgfile.img.xz | sudo dd bs=2M of=/dev/sdc status=progress
Use tar
with the special option --to-command
:
tar -xf imgfile.img.tar.gz --to-command="sudo dd bs=2M of=/dev/sdc status=progress"
Alternatively, you can pass options xfO
to tar
in order to send the ouput to stdout
and then you can pipe to dd
:
tar -xfO imgfile.img.tar.gz | sudo dd bs=2M of=/dev/sdc status=progress
Use unzip
with a pipe to dd
:
unzip -p imgfile.zip | sudo dd bs=2M of=/dev/sdc status=progress