- Let's first see if you have a remote key. Open a terminal and type
more ~/.ssh/id_rsa.pub
If a random string of letters and numbers appears, then you already have a public key and you can skip to step 3. - Don't have a public key? Let's make one! Open a terminal and type
ssh-keygen
to generate a public key. Just keep hitting enter. It's going to ask if you want to save the key to/Users/USER/.ssh/id_rsa
and to make a passphrase. You want to save it to the default location and don't worry about the passphrase, just hit enter. - Copy the public key to the remove computer with the command
ssh-copy-id [email protected]
What this is doing is copying your key to.ssh/authorized_keys
on artemis. - Now you can log into artemis without a password. Try this
ssh [email protected]
Now that we have remote login working, we can write a simple backup script that can use with crontab
.
rsync-backup.sh
is a simple script to backup a SOURCE
directory on artemis to DESTINATION
on your local
computer. This is nothing fancy and could (read: should) be improved.
#!/usr/bin/env bash
# ==================================================
# backup script using rsync
# r : backups up the source directory recusrively
# t : preserves the time stamp on the files
# e : excutes the ssh. "-e ssh" probably isnt necessary
#
# Notes:
# Want to see which files are transferred?
# then add --progress afer "-e ssh"
#
# L. Gloege 2018
# ==================================================
set -o errexit
set -o nounset
# Define source and destination directories
SOURCE=/local/data/artemis/workspace/gloege/test_directory
DESTINATION=/Users/gloege/backups
# Transfer files using rsync
rsync -rt -e ssh [email protected]:${SOURCE} ${DESTINATION}