Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I synchronize my code to a remote machine using ssh? [closed]

For a current course I am taking, we are using a remote computer to run our code.

I am coding locally on my MacBook and I'm looking for a good way to keep my local code up to date on the cluster.

The way I was doing it was to have a terminal open for running SCP to copy the directory, and another terminal that was SSH-ed into the cluster for making and running my code.

This seems less than optimal for me. Is there a way that I could automate the sending of the files to the cluster when they are modified?

Or am I stuck with the one-line command to move everything?

like image 577
Dan McClain Avatar asked Mar 19 '09 12:03

Dan McClain


People also ask

How to open remote SSH in VScode?

In VS Code, select Remote-SSH: Connect to Host... from the Command Palette (F1, Ctrl+Shift+P) and use the same user@hostname as in step 1. If VS Code cannot automatically detect the type of server you are connecting to, you will be asked to select the type manually.

Does rsync sync in both directions?

rsync works in one direction, so we need to run it twice to sync directories in both directions.


2 Answers

Your best option, other than a distributed version control, is using rsync over ssh. I keep a couple of machines in sync by doing the following on each one:

rsync -urltv --delete -e ssh /src.dir user@othermachine:/src.dir

You mentioned using a MacBook - rsync is on Mac OS X. As far as I know, it didn't need to be installed extra. And the beauty of rsync is that it looks for modifications and only copies modified files over. It doesn't do merging of simultaneous modifications like a distributed version control system would, but if you're like me where you do some work on your laptop then some work on your desktop, rsync is the best way to send all the changed files (and only the changed files) from one to the other when you switch modes.

Note: the rsync options used here are:

  • -u, --update skip files that are newer on the receiver
  • -r, --recursive recurse into directories
  • -l, --links copy symlinks as symlinks
  • -t, --times preserve modification times
  • -v, --verbose increase verbosity
  • --delete delete extraneous files from dest dirs, acts as --delete-during

lastly, -e is the option that allows you to specify your remote shell, in this case ssh

like image 143
Paul Tomblin Avatar answered Oct 21 '22 08:10

Paul Tomblin


If you can use rsync, that would probably be the best way.

Would using sshfs to (fuse) mount the remote folder(s) be an option? You could either edit the files directly, or use rsync, unison or any folder to folder synchronisation tool then.

like image 33
Evan Avatar answered Oct 21 '22 09:10

Evan