Tunnelling SSH/SCP through intermediate host when two hosts can’t directly communicate

Posted by & filed under Linux.

Scenario:

We need to scp a file between two hosts. The problem is that the two hosts (A & C) cannot directly communicate. We can solve this using a SSH tunnel and an intermediate host (B) that can communicate with both. This also means, the command for Host B needs to run first, then the scp command for host A.:

 

Host A (source)

This will scp to localhost on port 3000 which is actually our tunnel to host c — /destination_file is the path on host C

Host B (intermediate)

Host C (destination)

 

 

Also, if you have spaces in the paths make sure to escape the space with \ e.g.

 

BASH: Copy files recursively, excluding directories

Posted by & filed under Linux, Server Admin.

Scenario:

Folder /public_html looks like this:

I need to clone all the files and folders (with a couple of exceptions) in this directory into the /public_html/dev folder. We need to exclude the dev/ folder as it is the destination, and also want to exclude the dev2/ folder.

Rsync makes this easy:

In my scenario, something like the following gets the job done:

 

Creating large files on windows

Posted by & filed under Server Admin.

I typically use the dd utility in linux to create large files for testing various things. Today I needed to create a large file in a windows machine. One option is to use dd on a linux box to create the file, and then scp the file over to the windows box. This would work, but is a bit inefficient. After a bit of research I found that fsutil.exe will create files. Below is the same command in dd and fsutil:

dd:

fsutil:

Syntax is: fsutil file createnew <filename> <length in bytes>