m.divya.mohan
m.divya.mohan

Reputation: 2330

script to SSH to a machine and do SCP

I have a scenario -

I'll be logged in machineA. From there I need to ssh to machineB. From machineB I have to copy a file to machineC.

I'm trying to do this in a single step:

[user@machineA]$ ssh user@machineB "scp /path/to/file root@machineC:"

But this command fails with error:

Host key verification failed. lost connection

Could someone help?

I need this for a real use.

I do development in machineA, so I will be coding and cross-compiling here. I need to copy my cross compiled binary to machineC for testing. However, direct connection machineA --> machineC won't work. I need to use machineB in between.

Also, machineB and machineA are mirrored; so i don't have to explicitly copy my file from machineA to machieB. I don't use machineB for development just because it is in remote site and will be slow.

Upvotes: 1

Views: 1057

Answers (2)

dogbane
dogbane

Reputation: 274828

Use the -t flag so that a tty is allocated. You need this so that you can be prompted for a password to machineC.

ssh -t user@machineB "scp /path/to/file root@machineC:/path"

Upvotes: 5

JellyBelly
JellyBelly

Reputation: 2431

Use this

scp -P PORT USER@IP_SERVER:filename .

Upvotes: 0

Related Questions