How to use SCP on Linux or other UNIX-based Environment

SCP is used to copy files securely over network. In order to use SCP, the remote host must be configured to use SSH server (OpenSSH on Linux system, including Ubuntu) and the user must have an account on remote server.

scp syntax is easy,


local:~$ scp <source> <username>@<remote_host>:<destination>

Example for copying local file to the users home directory on remote host, you can replace mypapit with your own username

local:~$ scp id_rsa_.pub mypapit@remote.host:~/

id_rsa.pub 100% 392 0.9KB/s 00:00

local:~$

To list the file on the remote directory, just run

local:~$ ssh mypapit@remote.host ls

temp_file.txt id_rsa.pub

and the content of remote directory will be displayed.

Copying file recursively
To copy file recursively, you only need to add “-r” switch. Add -v for verbose output.

Example:

local:~$ scp -rv ~/* username@remote.host:~/backup

Conclusion
SCP is easy to use especially when you want to copy or upload files from client to server without the use of FTP server. Additionally, the content of the files transfered is encrypted over SSH communication and you get the benefit of simplicity while working on the console.

How to use rsync to backup and synchronize files to USB drive

Portable USB drive (sometimes called pendrive) has gained popularity as a medium for storing documents. Computer users would work on the files that they store on the usb drive and occasionally would copy them on their computer, or vice versa.

However this would cause problems if there’s a lot of files being worked on and transfered between usb drive and computers. Valuable time might be lost solely for identifying which of the files are more recent and need to be updated.

Fortunately there’s ‘rsync’, a tool which can be used to synchronize files between the computer and usb drive. Assuming you use Debian or Ubuntu, you only need to start ‘synaptic’ and select ‘rsync’ package. Once installed, start the terminal application and you can begin synchronizing the files using this command


$ rsync -r -vv /home/username/Documents/ /media/your_usb_drive

The general format of rsync command is :

$ rsync -r -vv <local document directory> <remote backup directory>

rsync only updates file which has been changed and would save time and precious harddisk space from maintaining duplicate files.

A Windows version is also available at : http://www.rsync.net/resources/binaries/cwRsync_3.1.0_Installer.zip

Quick Way to upgrade to Ubuntu 10.10 Maverick Meerkat

Ubuntu 10.10 Maverick Meerkat release is just around the corner!

Here’s how to upgrade Ubuntu 10.10 Maverick Meerkat using bash shell

sudo sed -i 's/lucid/maverick/g' /etc/apt/sources.list && sudo aptitude update && sudo aptitude dist-upgrade

sudo aptitude install update-manager-core
sudo do-release-upgrade -d

That’s it! Happy upgrading!

How to Import export MySQL database from command line

This tip would be useful for those who are either making backup of their remote mysql database or moving their web hosting to their provider.

Here’s how to export mysql DB to SQL file using command-line utility :
mysqldump –user=username –password=1234 –databases your_database –opt –quote-names –complete-insert > example.sql

Here’s how to import the SQL back into mysql database :
mysql –user=username –password=1234 –databases your_database –host=mysql_server host

Don’t forget to add your ip address to the list of allowable host on the remote MySQL server!