Search code examples
linuxsshscp

ssh config name alias not working for scp


I have this error when using scp:

scp -r h1:/dir1 h2:/dir1
ssh: Could not resolve hostname online1: Name or service not known
lost connection

But both ssh h1 and ssh h2 works well for I have config name alias in .ssh/config like this:

Host h1
  HostName 172.16.18.xxx
  User xxx

No editing on /etc/hosts. And I also use ssh-copy-id to work out the public key. Any idea of what's wrong?


Solution

  • When you use scp with no additional options like you here, remote h1 tries to directly connect to h2.

    h1 -> h2
    

    Since h1 need to know who h2 is, h1 needs the definition of h2. But you could also route it over your PC like

    h1 -> your pc -> h2
    

    using the option -3

    scp -r -3 h1:/dir1 h2:/dir2