[ad_1]
It’s always a challenge to move content (text) and files between a remote machine and localhost (local machine). The challenge becomes even harder when there is a bastion host or a Jumpserver in the middle that needs SSH (Secure Shell) access.
As I work day-in and day-out with virtual machines in Cloud, I am asked to send logs, copy or move files from the remote machine to local for debugging. In the linux world, coredump is required most of the time to see why a server or a component is crashing. Moving files like a core dump is required for debugging or understanding the state of the machine.
For this scenario let’s consider three machines (VMs or VSIs),
- Localhost
- Bastion host with a private IP – 10.10.0.13
- Remote machine / server with a private IP – 10.30.0.13
Scenario 1: copy a file from remote machine to localhost
You will be using SCP
(Secure Copy Protocol) from local to remote via Bastion.
-
Run this in one session/window/tab of the terminal on your local machine
ssh -L 1234:<REMOTE_PRIVATE_IP>:22 <OS_USER>@<BASTION_HOST_PRIVATE_IP> cat - ssh -L 1234:10.30.0.13:22 [email protected] cat -
-
In another session/window/tab,
scp -P <LOCAL_PORT> <REMOTE_USER>@127.0.0.1:<PATH_TO_THE_FILE_ON_REMOTE_MACHINE> <LOCAL_PATH_TO_COPY_FILE> scp -P 1234 [email protected]:/home/vmac/output.log output.log
Scenario 2: copy contents of a remote file to clipboard
On your local machine, run the below command to copy contents of a file to clipboard using pbcopy
ssh -J vmac@<BASTION_HOST_PRIVATE_IP vmac@<REMOTE_PRIVATE_IP> 'cat /home/vmac/output.log' | pbcopy
ssh -J [email protected] [email protected] 'cat /home/vmac/output.log' | pbcopy
References:
Happy learning and sharing 🙂
[ad_2]
Source link