How to sync files between computers without passwords

These instructions can be used to securely and automatically rsync files between 2 computers (Linux or Mac) either on your local network or even across the Internet using certificates/keys instead of passwords. Syncing files between 2 computers without using passwords is really not as difficult as it may seem, trust me!

The instructions below are combination of how-to guides I have found online and my own personal experience setting up syncing between computers.  This guide is written from the perspective of using Ubuntu Linux, but the majority of the commands would be the same on any flavor of Linux or even Mac OS X.

In this scenario I reference two computers:

Server A: This server is the remote host (the one that will be receiving files)

Server B: This server is the connecting host (the one that will be sending files).

Goal:

Automatically back up/rsync a folder from one Web server to the other every 10 min. securely but without passwords.

Step 1: Generate SSH Keys

  • Login to Server B (connecting host) as root
  • cd /home/%user% or cd /home
  • On connecting host (Server B), Generate keys:

ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
c1:17:3a:1d:d6:b7:ea:a1:d8:d7:38:91:76:02:d8:86 root@serverb.domain.com

Step 2: Create User on Server A

  • Login to Server A (remote host)
  • Create user on remote host: useradd %user%

Step 3: Copy Key Pair to Server A

  • Copy Key pair to home folder of user you just created From Server B (connecting) to remote host Server A (remote)

scp /root/.ssh/id_dsa* root@servera.domain.com:/home/%user%

Step 4: Install Keys/Certificate

Login as rsync user on Server A (remote) (**Hint: This is the user you created in Step 2**)

cd /home/%user%
su %user%
if [ ! -d .ssh ]; then mkdir .ssh ; chmod 700 .ssh ; fi
$ mv id_dsa.pub .ssh/
$ cd .ssh/
$ if [ ! -f authorized_keys ]; then touch authorized_keys ; chmod 600 authorized_keys ; fi
$ cat id_dsa.pub >> authorized_keys
$ cat authorized_keys

**Hint:  The last command in step 4 should list the authorized keys for that user.

Run ssh@%user%@servera.domain.com command from Server B (connecting). If it doesn't ask for a password, it worked!

Step 5: Install Rsync

Install rsync on source computer.  Instructions below are for Ubuntu.

apt-get install rsync

RSync Dry run

rsync -vzrtn -e ssh --delete %user%@servera.domain.com:sync_directory/ /path/to/other/directory/

**Hint:  Be sure that you are running rsync 3.07 or later. These options “- vzrtn” are what worked for me, but depending on what you need you may want to change them. Also keep in mind that the “- n” option is only for a dry run and should be removed when creating your script below in step 6.**

Step 6: Create Script and Cron Job

nano /bin/rsync.sh

Add rsync command. Be sure script is all on one line.

rsync -vzrt -e ssh --delete %user%@servera.domain.com:sync_directory/ /path/to/other/directory/

Step 7: Create Cron job

crontab-e

0,10,20,30,40,50 * * * * /bin/rsync.sh #Description…

The schedule above will run every 10 minutes.  There are lots of great articles online for how to modify Cron tab schedules to meet your needs.

How to Split Your Mac Hard Drive into 2 Partitions

If you’re like me, then you’re probably trying to figure out how to install OS X Lion on your Mac. The first requirement is that you have an extra partition on your Mac. Follow the instructions below to add a new partition to your Mac on the fly without formatting anything.

**WARNING: It should go without saying, but just in case, you should ABSOLUTELY TAKE A BACKUP before attempting any of the steps below.**

1. List Disks

Open the Terminal App and list your available disks by running:

diskutil list

Output:

Apple_HFS Macintosh HD            249.7 GB   disk0s2

2. Find Disk Identifier

The one you will split is probably called “Macintosh HD”, as shown above, although there will be 3 entries if you have a single partition. Each disk will have a disk identifier. Mine is disk0s2.

3. Check Min/Max Disk Size

Query your disk to find it’s min and max sizes by running this command and replacing “disk0s2” with your disk identifier:

diskutil resizevolume disk0s2 limits

Output:

For device disk0s2 Macintosh HD:
Current size:  249.7 GB (249715376128
Minimum size:  122.5 GB (122549932032 Bytes)
Maximum size:  249.7 GB (249715376128 Bytes)

4. Split your Boot Disc

Split your disk and make sure you don’t set your boot disk to less than the minimum. This can be run as many times as you want until you run out of space. In other words, if you want 3 disks instead of two split the disk again using the disk identifier of the newly created disk.

I want to make my boot disk 200GB and my Second (Lion) partition take up the rest of the space, about 50GB:

diskutil resizevolume disk0s2 200GB JHFS+ Lion 48G

The command causes the second partition to use the rest of the space on the disk, so just make sure that you specify a number, 48GB, that is less than the total available disk space after the split.

5. Dealing with Errors.

If you get an error like this then you should boot off your Mac’s startup disk, Open Disk Utility and click Repair Disk. Then re-run the command. You can even run it from terminal while booted off the install disc.

Started partitioning on disk0s2 Macintosh HD Verifying diskError: -9915: 
Could not modify partition map because filesystem verification failed

7. Now when I run diskutil list I see a new drive:

2:                  Apple_HFS Macintosh HD            200.0 GB   disk0s2
3:                  Apple_HFS Lion                     49.6 GB    disk0s3

8. If you have access to Mac OS X Lion you can now use this partition to install it.

Speed Up & Improve iPhoto ’09 Performance

Okay, since I updated to iPhoto ’09 (yes, I realize it’s currently 2010), I noticed a huge lag in performance upon opening the application.  Not only would it take long to load, but once the interface came up, if you tried to click around with your mouse, the rainbow wheel of death would start spinning.  Nobody likes that.  Follow these steps to improve and speed up iPhoto performance:

  1. Option + Command click the iPhoto application
  2. A box will pop up entitled: Rebuild Photo Library
  3. Check “Reclaim unused disk space from databases”
  4. Click “Rebuild”
  5. Checking any of the other ones doesn’t hurt either, it actually speeds it up even more.  Give it a try!

Also, if anyone has any additional advice or tips, please feel free to share.

Organize your dock by adding spacers in Snow Leopard

There is nothing like a shiny new mac and if you are like me, then you start with a fresh install rather then cloning your old machine. Since the dock on the new machine was not setup the way I like it a had to make a few changes and one of them is to add separators between applications. I do this to group like applications together. So to get started the first thing you will need to do is open Terminal on your Mac.

This is what my dock currently looks like.

Terminal can be found in: Applications > Utilities

To add a separator to the left side of the dock

defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'

To add a separator to the right side of the dock

defaults write com.apple.dock persistent-others -array-add '{tile-data={}; tile-type="spacer-tile";}'

Each time you run one of the commands above it will create a new separator but you need to restart the dock to see them. To do this just type this into Terminal:

killall Dock

Backblaze Icon Missing from Menu Bar in Snow Leopard

Long story short, Backblaze is awesome!  Up until I lost my Backblaze icon from the menu bar in Mac OSX Snow Leopard.  I researched online a little and couldn’t find an easy method of fixing the issue.  With that nifty little icon missing, I worried if it were working at all – all those precious photos, video and digital memories gone?

By going into the Backblaze settings in your System Preferences, you can select the check box next to “Show Backblaze icon in the menu bar.”  However, every time I checked the box, the icon would not come back.  And upon return to the preferences, the box remained unchecked.  A mystery?  Yes, indeed.

Therefore, I contacted customer support and they gave me a quick and easy solution that made my day.  Try the following steps below to fix the mysteriously missing Backblaze icon from the menu bar in Snow Leopard.

  1. Click on the Finder
  2. Press Command + Shift + G
  3. Enter /Library/Backblaze in the text field and press “Go”
  4. Right click on the folder “bzdata” and Get Info (or press command + i)
  5. Change the permissions, so that all users have “Read & Write” permissions.
  6. Then click the gear icon and select “Apply to enclosed items..”
  7. If the Backblaze icon doesn’t show up on the menu bar, follow steps 1-3 again and this time double click “bzbmenu” and this will place the icon in the right spot.