Scp router; take file on PC from router

Hi,

I would like to copy File with SCP in script.
I explain here, from router ssh session, the script is running from router, i need to SCP to my PC, and take the file to my router.

But what I try does not work, cause I can’t exit from my script or I cant stop router ssh session to SCP PC to router.
I need to stay in my router session and take file and bring it back, is it possible?

scp uses and respects
users
and
user accounts - and their correct names

if you want to copy to your router
you need to know whether the user account there is called “root” - or something else, like “admin”

Then you can send your scp to:
scp admin@router.ip
instead of just sending it to the router (or it’s IP)
from your user account
which is not known there, on the router

… include the target account and possibly also the target directory … in the scp command …

1 Like

For exemple in my case.
The file on my PC is here : /media/jack/vpn.conf
And must goes to : root@192.168.1.1:/etc/torguard on router

and what command did you try to do that
which apparently dd not work?

root@OpenWrt:~# scp jack@localhost:/run/media/jack/D/vpn.conf root@192.168.1.1:/etc/torguard/
jack@localhost's password:

My password from my linux session does not work on that.

of course not
user “jack” is not known on the router

you need the password for “root” on the OpenWRT router
which is likely to be different …

scp /run/media/jack/D/vpn.conf root@192.168.1.1:/etc/torguard
should be how to do it - from memory

You will get prompted for that (root) password on the router.

root is likely to be the one and only account on the OpenWRT router

but, /run/media/jack/D/vpn.confis on my pc, and I’m running script from my router, so from my router if I run : scp /run/media/jack/D/vpn.conf scp will looking for file into router, not?

anyway, scp /run/media/jack/D/vpn.conf root@192.168.1.1:/etc/torguard it is what I tried in first, and the answer is, * No such file or directory
*

so, you are on your router
logged into your router
and you want to copy a file
which is residing on your PC (in some directory)
to the router

This seems overly complicated to me.

You are on your PC - connected to your router.
Why not do it from your PC- instead of first going into your router
and then trying to copy a file from your PC - what is essentially a remote machine at this point?

What I wrote was assuming that you initiated the transfer from your very ordinary user account on your PC - to the router …

1 Like

I try to do that, that way, cause I’m running a script and the script must be on the router, and during script I need to take that file from my pc.

in that case, to be able to have your router connect to your PC, you have to have the sshd service running on your PC - so that the router can connect to the PC

and you need the IP of your PC in your command
and the path
to get the file
and then transfer it back to the router

scp jack@localhost

will not do - you need to give your router the IP of your machine to connect to

from the routers POV,
where you run your script from,
your PC (where the file is at)
is not localhost,
your PC is a remote machine to it
and you need to supply the IP of it

1 Like

yep, this one worked but it asks me my linux password, and I would have to add it somehow in the script but don’t know how?
thanks

I do not know the answer to that one - not even how to (crudely and insecurely) write it in clear text into the command.

ssh keyfile authentication (instead of password auth) might be the solution
I don’t know - not yet :wink:

set up key file authentication between the two computers
and it should then work with a script as well

I know that it works from PC to the router.
I see no reason for setting it up in the other direction would be more difficult.
Esp. with OpenWRT.
They are both Linux.

1 Like

Hi again,

do you know why after y/n question in the shell, nothing happens eveytime, look here ;

root@OpenWrt:~# sshpass -p 'XXXXXX' scp -r jack@192.168.1.11:/run/media/jack/xxxxxx /etc/xxxxxx/

Host '192.168.1.11' is not in the trusted hosts file.
(ssh-ed25519 fingerprint sha1!! 63:d8:6f:58:0xxxxx;xxxxx;xxxxxx;xxxxxxxxx::52)
Do you want to continue connecting? (y/n) y

after y, nothing

I’m not so sure that your assessment that nothing happened is correct.
If you connect again, you will not be asked the same question,
because now, the host is in the trusted hosts file.
Because you said yes to the question.

Instead of using sshpass, which I don’t know, I’d much prefer to use ssh key files.
No password necessary and you only set it up once.
But that is just me.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.