2. Running a local script on a remote machine (or remote on local)

Got a script written on your computer and want to test it out really quickly? No need to push the file to it or anything like that. Just pipe your local file through SSH and run it this way instead!

ssh remoteuser@ip.address.of.server 'bash -s' < scriptfile.sh

With this command you remove the need to push files around to remote machines to execute shell scripts. It saves a lot of time in the long run.

3. Remote hard drive backup

Want to back up your computer to your remote machine without taking the hard drive out physically and hooking it up? It’s easy to do, and with an SSH pipe, no less. Here’s how it works:

sudo dd if=/dev/sda | ssh remoteuser@ip.addresss.of.remote.machine 'dd of=sda.img'

This makes use of the dd command. It uses your local drive (sda) as the source, and then it pipes the output over SSH to be written to a raw image file.

 

Note: The drive you may want to back up might have a different denotation. Use the lsblk command to figure out what drive you’re looking to back up. This command will tell you what /dev/ to use in the if= part for the command above.