I work at a university, and we have a remote machine(1) that I ssh into.

To do this from my laptop, I believe that I have to first ssh into the university system and then ssh into the particular machine. This all happens automatically for me because the ssh config file has been set up for me. I just type:

ssh -Y comp_name

and I'm in.

I'm currently trying to ssh FROM a totally unrelated remove machine(2) - nothing to do with the university. To ssh from this into my remote_machine(1), I do two separate ssh's:

1. Into the university (ssh-gateway)
2. Into remote_machine(1)

So far so good.

What I want to do is to transfer a file using scp from remote_machine(2) to remote_machine(1). How do I do this when there are these two steps involved?

I initially tried:

scp ./file.txt username@ip_of_remote_machine(1)

but it says

connection refused

I think this is because I need to go into the university network first.

I know my terminology isn't correct, but hopefully you understand what I mean.


First, you do not need to login to remote_machine(1) in two steps ever: the following command

  ssh -t me@universitygateway ssh me@remote_machine(1) 

will do it for you, if you have enabled (as I seem to understand) passwordless login.

As for scp'ing, you can do it as follows:

 scp -o ProxyCommand="ssh me@universitygateway nc remote_machine(1) 22"  remote_machine(1):/path/to/file/to/download .
  • Thank you! Very helpful. I was prompted for the university gateway password, which I gave, but then I got the error message "nc: getaddrinfo: Name or service not known" Nov 2 '15 at 14:52
  • I have the authorisation keys set up on my laptop. But I supposed because I am copying from remote_machine(2) to remote_machine(1), I will be prompted for the passwords. But this is fine because I know the passwords. Doesn't the error message relate to something else? Nov 2 '15 at 14:57
  • and yes, I had "nc myusername@ip_of_remote_machine(1) 22" Nov 2 '15 at 14:58
  • Oh I tried it without the myusername@ and just the ip address. That worked! Thank you so much :) Nov 2 '15 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.