Saturday, September 18, 2010

rSync-ing files from your local to a remote (Ubuntu) host

Prerequisites:
1. On the local computer, Ubuntu 10.04 desktop installed.
2. On the remote, Ubuntu 10.04.1 Server edition installed. Configured simply as an OPENSSH server.

Objective:
Backup my Thunderbird files located at /home/user/.thunderbird to the remote host.
Use the fantastically fast rsync command to quickly sync folders between my local machine and remote host. Connect securely by ssh.

Steps:
1. Create ssh keys for my desktop & server, so my ssh connection won't need to ask for passwords everytime I connect to the server.
On my desktop Ubuntu terminal window, generate the public/private key pair. Accept default values, hitting Enter for all the prompts asked. This would mean accepting the default file name for the key, and having an empty passphrase:
ssh-keygen -t dsa
Move the public key over to the remote host:
ssh-copy-id username@remotehost
replacing username for your actual user name, and remotehost with the IP address of the server, like
ssh-copy-id lavezarez@10.42.43.10
A possible pitfall to avoid - ensure you have the same user name on BOTH your local and server machines.
Login to the server via ssh, and ensure correct permissions to the public key.
ssh lavezarez@10.42.43.10
chmod 600 .ssh/authorized_keys

2. Create the backup destination folder in the server.
You may use Nautilus to connect via SFTP to the server. Press Ctrl-L to open up the location bar, and type sftp://username@remotehost (e.g. sftp://lavezarez@10.42.43.10)
Open up the extra pane (on the View menu of Nautilus) or hotkey F3. That way you can see folders on your local and server machines at the same time, much like winscp for Windows.

You may want to change permissions for the new folder using chmod. Octal 750 is a usual permission value.

3. Finally the rsync. Here's a sample executable script -
#!/bin/sh
rsync --progress -avhe ssh --delete /home/lavezarez/.thunderbird/ lavezarez@10.42.43.10:emailbackup/
echo -n Press return to continue...
read ans

---
An initial rsync for a 3gb-sized folder took about 4 minutes to transfer to the server, running on a typical 100mbps LAN connection.

Running the rsync after that completes the transfer process much faster, under 5 seconds, 10 seconds, etc. depending on what files changed in the source.

---
Changing ssh servers:
Should you change one server with another, while maintaining the same IP address, you must clear your /home/<user>/.ssh/known_hosts file before attempting to ssh to that server.

Thursday, September 16, 2010

How to configure a static IP address in an Ubuntu machine

Edit the /etc/network/interfaces file
sudo nano /etc/network/interfaces

and change the following lines
# The primary network interface
auto eth0
iface eth0 inet dhcp

into a similar pattern as:
auto eth0
iface eth0 inet static
address 10.0.0.100
netmask 255.255.255.0
gateway 10.0.0.1

Wednesday, September 15, 2010

backup up a windows desktop to an ubuntu server

Prepare the server. Install Ubuntu Server 10.04.1, and choose the OPENSSH option for server type.

On Windows client:
- install cwRsync
- create your working folder for rSync, e.g. c:\sshstuff
- copy the cwrsync.cmd batch template from cwrsync's install folder to the working folder
- set the windows system environment PATH variable to include the cwRsync folders
- get the user name, e.g. lavezarez

On the Ubuntu server:
Create a user id to user for ssh rsync operations.
- modify the /etc/adduser.conf file and change -> DIR_MODE=0750
- create the user ID
sudo adduser backuper
and follow the prompts.

Below are repetitive steps for each Windows machine to backup:

Back on the windows client:
- Generate ssh public & private keys
ssh-keygen -q -b 1024 -t rsa -f cwrsync -N '' 
Assign a unique file name for the key. It shouldn't be cwrsync all the time.
- via winscp
Create the destination folder for the Windows machine's files.
Copy the pub key to the ubuntu server (via winscp or other means), at /home/user location. Multiple desktops to backup can have a SINGLE Ubuntu user login, having multiple pub keys.

back on the ubuntu server:
- logged on with the windows user's name,

these steps untested, from cwRsync FAQ --
mkdir -p .ssh
cat cwrsync.pub > .ssh/authorized_keys
ln -s .ssh/authorized_keys .ssh/authorized_keys2
chmod 755 home/backuper home/backuper/.ssh
chmod 644 home/backuper/.ssh/authorized_keys
chown backuper.ssh .ssh/authorized_keys

You only have to do all these steps the first time. The only step you repeat for each Windows machine is the cat command.

For 2nd and other Windows machine, the pub key must be copied to Ubuntu and appended to its authorized_keys2, much like:
->copy the foo.pub file via winscp to Ubuntu server.
->ssh ubuntu server, login as the backuper user
then type:
cat foo.pub >>~/.ssh/authorized_keys2

This tip taken from this site.

It may also be easier for you to set the permission octals and ownership using winscp.

back on the windows:
Create backup folder in ubuntu via winscp
then try the rsync NOW!

Typical rSync options: --progress --delete -avhe "ssh -i /cygdrive/c/sshbackup/mykey"
where sshbackup is the folder where the private ssh key is stored in Windows
and mykey being the actual private ssh key file.

References:
cwRync reference
Ubuntu server openssh reference
Ubuntu server adding users reference

Sunday, September 5, 2010

Installing Tomcat 6 in Ubuntu 10.04

New adventure - Java web application development.

Packages installed so far:

sudo apt-get install tomcat6 tomcat6-common tomcat6-examples tomcat6-docs tomcat6-admin