Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ssh config name alias not working for scp [closed]

Tags:

linux

scp

ssh

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?

like image 234
schemacs Avatar asked Sep 04 '13 03:09

schemacs


People also ask

Can SCP use SSH config?

One of the added benefits of using ssh's config file is that programs like scp, rsync, and rdiff-backup automatically pick up these options also and work just as you'd expect (hope).

How do I access SSH config?

The ssh program on a host receives its configuration from either the command line or from configuration files ~/. ssh/config and /etc/ssh/ssh_config . Command-line options take precedence over configuration files. The user-specific configuration file ~/.


1 Answers

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
like image 102
Tschwen Avatar answered Sep 21 '22 23:09

Tschwen