Using SCP to transfer files

Using SCP is a great way to transfer files from one machine to another. SCP uses SSH and can move files to/from localhost remotehost or remotehost remotehost.
SCP Syntax: localhost -> remotehost

scp /path/to/source-file user@host:/path/to/destination-file

SCP Syntax: remotehost -> remotehost

scp user@src-host:/path/to/src-file user@dest-host:/path/to/dest-file

SCP Examples

scp file.txt mydomain.com:~/mydir/file.txt
 
scp local_dir/filename myname@host1:remote_dir
 
scp local_dir/* myname@host1:remote_dir
 
scp myname@host1:remote_dir/filename .
 
scp myname@host1:remote_dir/filename myname@host2:another_dir

Recover the MySQL Root Password in Linux

Step 1 – At the linux shell, stop the current mysqld process, start the mysqld_safe process with –skip-grant-tables switch and login as root (no password).

/etc/init.d/mysql stop
mysqld_safe –skip-grant-tables &
mysql -u root

Step 2 – At the mysql shell set the root password and flush privileges.

USE mysql;
UPDATE user SET password=PASSWORD("new-password-here") WHERE User=’root’;
FLUSH PRIVILEGES;
QUIT;

Step 3 – Back at the [...]

Using Rsync over SSH

Prerequisites

First make sure that you are able to login to the remote host using ssh key authentication.

Basic Syntax

To sync files from a local directory to a remote directory use the following syntax:

rsync {options} -e ssh {source} {dest}

Example

Here is an example that exclude all .psd and .fla files:

rsync –exclude *.psd \
[...]

Using tar and gzip to Compress Files and Directories

Create and Compress and Archive
Archive a group of files:

tar -czvf archive.tar.gz file1 file2 file3

Archive an entire directory:

tar -czvf archive.tar.gz directory/

Extract a Compressed Archive

tar -xzvf archive.tar.gz

List the Contents of a Compressed Archive

tar -tzvf archive.tar.gz

Common tar Switches

-c create a new archive
-x extract files from an archive
-t list the contents of an archive
-z filter the archive through gzip
-v [...]

SSH Login Using Public Key Authentication

Step 1: Generate Keypair on Localmachine

ssh-keygen -t dsa

When prompted for a passphrase you can leave it empty to enable logging in without a password (please note that there are potential security issues with doing this).

After confirming your passphrase at the second prompt you’ll find two new files (the keypair) in your ~/.ssh directory. The [...]