[LINUX] How to send a file in one shot by connecting to a host on the other side of the platform with SCP in multiple stages

--Environment --Connection source - CentOS Linux release 7.6.1810 (Core) - OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017 --Step host: Amazon Linux release 2 (Karoo) --Location host: Red Hat Enterprise Linux Server release 5.11 (Tikanga)

What I want to do: I want to transfer files to the storage host on the other side of the platform in one shot

It is troublesome to transfer files from the connection source to the stepping stone, from the stepping stone to the storage place. 2020-04-03 17.18.36.jpg

Multi-stage connection using Proxy Command on SCP

--Reference --ssh / scp multi-stage connection ~ Beyond the bastion server ~ --Qiita -Multi-stage scp connection via stepping stone with key authentication --Kabegiwa Blog

format


#Example) Transfer all files with the extension jar in a specific directory
# -r :Recursively copy in the directory.
# -o :setting file(ssh_config)Pass options to ssh in the format used in
# -W : %h and%Replace p with the original destination and its port
$ scp -i {Storage key} -r -o ProxyCommand='ssh -i {Step key} -W %h:%p {Stepping stone user}@{Stepping stone address}' {Your directory path}/*.jar {Storage user}@{Storage address}:{Storage directory path}

I tried it

Similarly with SSH, if you connect in multiple stages using ProxyCommand, you can log in to the host on the other side of the platform with a single shot.

#Transfer files with SCP
$ scp -i ~/.ssh/fumidai.pem -r -o ProxyCommand='ssh -i ~/.ssh/okiba.pem [email protected] -W %h:%p' /home/ponsuke/HOGE.war [email protected]:/tmp/.
Enter passphrase for key '/home/ponsuke/.ssh/fumidai.pem':
Enter passphrase for key '/home/ponsuke/.ssh/okiba.pem':
HOGE.war                                                                                                                   100%   38MB  44.2MB/s   00:00
Killed by signal 1.

#I will go to check the file that was connected to SSH
$ ssh -i ~/.ssh/fumidai.pem -o ProxyCommand='ssh -i ~/.ssh/ponsuke.pem [email protected] -W %h:%p' [email protected]
Enter passphrase for key '/home/ponsuke/.ssh/fumidai.pem':
Enter passphrase for key '/home/ponsuke/.ssh/okiba.pem':
Last login: Thu Apr  2 14:49:44 2020 from 10.0.3.182
#Was sent properly
$ ls /tmp/
HOGE.war

Recommended Posts

How to send a file in one shot by connecting to a host on the other side of the platform with SCP in multiple stages
How to set a shared folder with the host OS in CentOS7 on VirtualBOX
How to drop Google Docs in one folder in a .txt file with python
How to get a list of files in the same directory with python
How to display the modification date of a file in C language up to nanoseconds
How to identify the element with the smallest number of characters in a Python list?
How to check in Python if one of the elements of a list is in another list
A memo on how to overcome the difficult problem of capturing FX with AI
How to register the same data multiple times with one input on the Django management screen
How to plot a lot of legends by changing the color of the graph continuously with matplotlib
How to adapt multiple machine learning libraries in one shot
How to check ORM behavior in one file with django
How to intercept or tamper with the SSL communication of the actual iOS device by a proxy
Process the contents of the file in order with a shell script
How to handle multiple versions of CUDA in the same environment
How to check the memory size of a variable in Python
How to make a command to read the configuration file with pyramid
How to check the memory size of a dictionary in Python
How to output the output result of the Linux man command to a file
How to get the vertex coordinates of a feature in ArcPy
How to send a request to the DMM (FANZA) API with python
How to calculate "xx time" in one shot with Python timedelta
How to convert 0.5 to 1056964608 in one shot
How to debug a Python program by remotely connecting to a Docker container in WSL2 environment with VS Code
How to run the practice code of the book "Creating a profitable AI with Python" on Google Colaboratory
I tried to open the latest data of the Excel file managed by date in the folder with Python
A memo organized by renaming the file names in the folder with python
How to send a visualization image of data created in Python to Typetalk
How to specify a .ui file in the dialog / widget GUI in PySide
[Introduction to Python] How to sort the contents of a list efficiently with list sort
I want to sort a list in the order of other lists
How to put a line number at the beginning of a CSV file
I made a program to check the size of a file in Python
How to sort by specifying a column in the Python Numpy array.
How to get the "name" of a field whose value is limited by the choice attribute in Django's model
How to save the feature point information of an image in a file and use it for matching
I wanted to know the number of lines in multiple files, so I tried to get it with a command
Various ways to read the last line of a csv file in Python
How to pass the execution result of a shell command in a list in Python
Feel free to write a test with nose (in the case of + gevent)
How to mention a user group in slack notification, how to check the id of the user group
How to publish a blog on Amazon S3 with the static Blog engine'Pelican'for Pythonista
How to plot multiple fits images side by side in galactic coordinates using python
Find out how to divide a file with a certain number of lines evenly
To output a value even in the middle of a cell with Jupyter Notebook
How to count the number of elements in Django and output to a template
How to access the contents of a Linux disk on a Mac (but read-only)
[python] How to sort by the Nth Mth element of a multidimensional array
A memorandum of how to execute the! Sudo magic command in Jupyter Notebook
Checklist on how to avoid turning the elements of numpy's array with for
[Introduction to Python] How to get the index of data with a for statement
How to calculate the volatility of a brand
How to read a CSV file with Python 2/3
How to send a message to LINE with curl
How to create a JSON file in Python
Save the object to a file with pickle
How to read a file in a different directory
How to list files under the specified directory in a list (multiple conditions / subdirectory search)
How to start the code written in Atom with one command without starting teminal
[Django] Test to send a file by POST and check the returned context [TDD]
[Ruby] How to replace only a part of the string matched by the regular expression?