I would like to copy stuff in bulk (reimage disk using dd
) with netcat from host A to B via ssh encrypted channel on Linux.
What commands should I type on both ends?
dddisk-imagenetcatssh-tunnel
I would like to copy stuff in bulk (reimage disk using dd
) with netcat from host A to B via ssh encrypted channel on Linux.
What commands should I type on both ends?
Best Answer
Copying from source to target where target has sshd running:
dd if=/dev/sda | gzip | ssh root@target 'gzip -d | dd of=/dev/sda'
Copying from source to target via sshd_host when target is not running sshd.
nc -l -p 62222 | dd of=/dev/sda bs=$((16 * 1024 * 1024))
ssh -L 62222:target:62222 sshd_host &
Source:
dd if=/dev/sda | nc -w 3 localhost 62222
dd - if= is the source, of= is the destination, bs= is the block size. Different block sizes may improve performance. 16 is usuually a fairly reasonable starting point. You can also use count= to indicate how many blocks to copy.
nc - -p indicates the port to use for services. -l is used to start a service. -w sets up the time to wait for data in the pipline before quiting.
ssh - -L sets up the tunnel on the remote host. The format of the argument is,
local_port:target_host:target_port
. Your local program (nc) connects to the local_port, this connection is tunneled and connected to target_port on the target_host.The options defined are just the ones used for this. Look at the man pages for more details.
A few notes:
source machine dd -> nc -> ssh -> ssh tunnel -> sshd server -> nc on target -> dd