Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
scp from one host to another [Solved; Workaround]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Fri Jan 03, 2014 2:13 pm    Post subject: scp from one host to another [Solved; Workaround] Reply with quote

Edit: Solution obtained via workaround mentioned by @kurly: Add -3 argument to scp to do the transfer via local machine.

Original Post/Problem:
Recently I thought of this crazy method of transferring a file from one host to another via scp. I have publickey access (without password) to both hosts, and scp works in transferring files from local machine to either of the remote hosts and vice versa. But the following fails:
Code:
~» scp host1:filename host2:.
ssh: Could not resolve hostname host2: Name or service not known
lost connection
Whoops! So, maybe I need to give the full hostname along with domain name? Both are in the same LAN and have the same domain
Code:
~ [1] » scp host1.domain:filename host2.domain:.
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
lost connection
So, even though I have passwordless publickey logins to both places, it seems scp can not transfer a file from one host to another! I am just curious about this behavior.
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/


Last edited by ppurka on Sun Jan 05, 2014 1:02 pm; edited 1 time in total
Back to top
View user's profile Send private message
sabayonino
l33t
l33t


Joined: 03 Jan 2012
Posts: 671

PostPosted: Fri Jan 03, 2014 5:47 pm    Post subject: Reply with quote

basically
Code:
$ scp /<local>/<file>  user@host_domain:/<remote>/<directory>/<filename>


to copy file1 from your local folder to remote host

From local user to LAN host
Code:
$ scp file1 <user>@192.168.1.40:/home/<user>/filename


From local user to Remote Host by domain name
Code:
$ scp file1 <user>@domain_name.org:/home/<user>/filename



see
Code:
 man scp


Quote:
[...]SYNOPSIS
scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 ... [[user@]host2:]file2
[...]

_________________
BOINC ed il calcolo distribuito
Back to top
View user's profile Send private message
666threesixes666
Veteran
Veteran


Joined: 31 May 2011
Posts: 1248
Location: 42.68n 85.41w

PostPosted: Fri Jan 03, 2014 6:56 pm    Post subject: Reply with quote

i use sftp and file managers.... im pretty sure there is an sshfs to where you can mount remote directories as if they are local in portage.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 42596
Location: 56N 3W

PostPosted: Fri Jan 03, 2014 8:28 pm    Post subject: Reply with quote

ppurka,

When you scp between hosts A and B while sitting at host C you need the same password/key on both hosts A and B.
At least, thats the only way I have made is work
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Sat Jan 04, 2014 6:15 am    Post subject: Reply with quote

NeddySeagoon wrote:
ppurka,

When you scp between hosts A and B while sitting at host C you need the same password/key on both hosts A and B.
At least, thats the only way I have made is work
Actually, I have the same login, and publickey on both hosts A and B! I think it is a limitation of scp.

Using sshfs is of course a possibility. I was just curious why this didn't work.

Edit According to the manpage this shouldn't have failed:
Code:
     File names may contain a user and host specification to indicate that the file is to be copied to/from
     that host.  Local file names can be made explicit using absolute or relative pathnames to avoid scp
     treating file names containing ‘:’ as host specifiers.  Copies between two remote hosts are also per‐
     mitted.

_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
gotyaoi
Tux's lil' helper
Tux's lil' helper


Joined: 01 Apr 2013
Posts: 137

PostPosted: Sun Jan 05, 2014 12:18 am    Post subject: Reply with quote

A couple thoughts, in no particular order:

  • Do you have an agent running on host 1 with the required key?
  • If you're ssh'd in to host 1 to run the scp, are you using agent forwarding?
  • Can you ssh from host 1 to host 2?
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 6968

PostPosted: Sun Jan 05, 2014 6:00 am    Post subject: Re: scp from one host to another Reply with quote

ppurka wrote:

[code]~» scp host1:filename host2:.
ssh: Could not resolve hostname host2: Name or service not known

Well it just tell you host2 is not known, to jump from host1 to host2 you need host2 in host1 resolv.conf, but as soon as you have jump in host2, to jump to host3 : host2 resolve.conf must known host3, and it won't work even if host1 knows host3

I'm not sure what you are trying to do, copying to . is the same as doing [code]scp that host2[/code], no need to tell host2:.
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Sun Jan 05, 2014 6:40 am    Post subject: Reply with quote

gotyaoi wrote:
A couple thoughts, in no particular order:

  • Do you have an agent running on host 1 with the required key?
  • If you're ssh'd in to host 1 to run the scp, are you using agent forwarding?
  • Can you ssh from host 1 to host 2?
No ssh-agent is running anywhere.

I can not ssh from host 1 to host 2 with pubkey. I can do the ssh with password.
krinn wrote:
ppurka wrote:

[code]~» scp host1:filename host2:.
ssh: Could not resolve hostname host2: Name or service not known

Well it just tell you host2 is not known, to jump from host1 to host2 you need host2 in host1 resolv.conf, but as soon as you have jump in host2, to jump to host3 : host2 resolve.conf must known host3, and it won't work even if host1 knows host3
I don't understand your point. Everything is under the same domain/LAN.
Quote:

I'm not sure what you are trying to do, copying to . is the same as doing [code]scp that host2[/code], no need to tell host2:.
It won't make a difference if I use :. or not.
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 6968

PostPosted: Sun Jan 05, 2014 6:51 am    Post subject: Reply with quote

My point is that you should just read what it tells you, and it tells you the host is unknown.
So your host resolution isn't working like you think.

The fact they are on the same domain just grant you ability to not specify the domain : ie my domain is "locdom" so i don't need to says "thathost.locdom" and just use "thathost" and it will assume looking at this one first.
but if it cannot resolve "thathost" or "thathost.locdom" you'll end with the same error : unknown host.

try scp -v it should tell you the resolved host ip, that's what that fail for you.
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Sun Jan 05, 2014 7:37 am    Post subject: Reply with quote

krinn wrote:
My point is that you should just read what it tells you, and it tells you the host is unknown.
So your host resolution isn't working like you think.

The fact they are on the same domain just grant you ability to not specify the domain : ie my domain is "locdom" so i don't need to says "thathost.locdom" and just use "thathost" and it will assume looking at this one first.
but if it cannot resolve "thathost" or "thathost.locdom" you'll end with the same error : unknown host.

try scp -v it should tell you the resolved host ip, that's what that fail for you.
thanks. I can understand that. But the second command also fails, where I give the full host.domain format. I guess, the two issues are unrelated?
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
kurly
Apprentice
Apprentice


Joined: 02 Apr 2012
Posts: 253

PostPosted: Sun Jan 05, 2014 7:58 am    Post subject: Reply with quote

Does the -3 flag for scp help? This will redirect the transfer through the local machine. It should not be necessary though if host1 and host2 can see each other.
Back to top
View user's profile Send private message
gotyaoi
Tux's lil' helper
Tux's lil' helper


Joined: 01 Apr 2013
Posts: 137

PostPosted: Sun Jan 05, 2014 8:01 am    Post subject: Reply with quote

ppurka wrote:
No ssh-agent is running anywhere.

I can not ssh from host 1 to host 2 with pubkey. I can do the ssh with password.


Hmm. Since you're not using -i, is your private key in the default location (~/.ssh/id_{rsa,dsa} or something, check the -i option in the ssh man page) on the initiating host?.
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 6968

PostPosted: Sun Jan 05, 2014 8:35 am    Post subject: Reply with quote

ppurka wrote:
I can understand that. But the second command also fails, where I give the full host.domain format. I guess, the two issues are unrelated?

Well, not the same error, so chance they are related are low, but still they could share same root cause : if you badly set hosts resolution, you could even have host1.domain and host1 resolving to two different hosts...
Public key is also store without domain, and as you should have copy public key from an host to others host, the key is without domain.
So thatusers@thathost.thatdomain is not record in your key, but only thatuser@thathost.
- Something host1 connecting to the host2 should complain as it knows who is "user@host2" but not who is "user@host2.domain" yet, but offering you to connect to it still.
- Something that never bug host2 as when ssh or scp to it you cannot send your domain (well if not using -i), so host2 see thatuser@host1
- But that's something that change from copying from 2 hosts as now you tell host2 the one connecting is thatuser@host3.domain : and this can be denied if you have only thatuser@host3 set inside host2:authorized_keys file.
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Sun Jan 05, 2014 12:59 pm    Post subject: Reply with quote

kurly wrote:
Does the -3 flag for scp help? This will redirect the transfer through the local machine. It should not be necessary though if host1 and host2 can see each other.
Excellent! This works!
gotyaoi wrote:
Hmm. Since you're not using -i, is your private key in the default location (~/.ssh/id_{rsa,dsa} or something, check the -i option in the ssh man page) on the initiating host?.
Hmm.. -i ~/.ssh/<private key> does not work. I have both the hosts in my .ssh/config and the keyfile, login names, etc are all mentioned there.
Code:
Host host1* host2*
    ControlPath          ~/.ssh/master-%r@%h:%p
    ControlMaster        auto
    Compression          yes
    ForwardX11           yes
    ForwardX11Trusted    yes
    IdentityFile         ~/.ssh/private_key
    #GSSAPIAuthentication no
    User                 username
    PreferredAuthentications publickey,password

_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum