Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Created September 17, 2010 16:42
Show Gist options
  • Save xeoncross/584499 to your computer and use it in GitHub Desktop.
Save xeoncross/584499 to your computer and use it in GitHub Desktop.
Work with files over SSH
# Forward all traffic on localhost port 3333 to MySQL on the remotehost
ssh user@remotehost -L 3333:127.0.0.1:3306
# or add it to .bashrc
alias remote_db='ssh user@remotehost -L 3333:127.0.0.1:3306'
# Copy a directory to another machine using SSH
rsync -a -e --delete ssh source/ username@remotemachine.com:/path/to/destination/
# If a file was originally in both source/ and destination/ (from an earlier rsync, for example),
# and you delete it from source/, you probably want it to be deleted from destination/ on the next
# rsync. However, the default behavior is to leave the copy at destination/ in place. Assuming you
# want rsync to delete any file from destination/ that is not in source/, you'll need to use the --delete flag:
rsync -a --delete source/ destination/
# Copy a file from a server to your computer
rsync -a -e ssh user@site.com:/var/www/file.php /home/user/file.php
# Copy folder from server to current folder
rsync -arve ssh user@site.com:/var/www/ ./
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment