What's new

Copy files to USB HDD via ssh

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

crashtext

New Around Here
Hi everyone,

I've been lurking for a while and installed Merlin's excellent 270.26b about a month ago (Thank you Merlin!).

I have an HTPC running OPENELEC and I want to transfer files to a HDD connected to the RT-N66U. I am accessing the HTPC via Putty from a Windows box which I can log in to, but I am a complete Linux noob and can't find the right command for transferring the file.

I think it's something like:
Code:
scp filename admin@RT-N66U:/harddrive/directory

This times out with:
Code:
ssh: connect to host RT-N66U port 22: Connection timed out lost connection

Can anyone help me out with this please? And don't I need to give the router password somewhere?

Many thanks
 
You need to enable SSH on the Administration -> System page to be able to use scp.
 
Doh, I should have looked for a setting in your firmware. Thanks.

However I'm still having problems...

Code:
scp test.txt admin@192.168.1.1:/Elements

asks for password, but then gives:

Code:
scp: /Elements: Read-only file system

or if I try:

Code:
scp test.txt admin@192.168.1.1:/Elements/

I get:

Code:
scp: /Elements/: is a directory


Can you help me where I'm going wrong please?
Do I need to give write permissions for my OpeneElec to write to the HDD, and If so how?

Please explain in very simple terms please. Thanks!

EDIT: admin already has r/w access to the hdd. I am very confused.
 
Last edited:
Doh, I should have looked for a setting in your firmware. Thanks.

However I'm still having problems...

Code:
scp test.txt admin@192.168.1.1:/Elements

asks for password, but then gives:

Code:
scp: /Elements: Read-only file system

or if I try:

Code:
scp test.txt admin@192.168.1.1:/Elements/

I get:

Code:
scp: /Elements/: is a directory


Can you help me where I'm going wrong please?
Do I need to give write permissions for my OpeneElec to write to the HDD, and If so how?

Please explain in very simple terms please. Thanks!

EDIT: admin already has r/w access to the hdd. I am very confused.

Your hard disk can't be mounted as /Elements. It will be something under /mnt. Connect through SSH and see the content of /mnt to determine the mount point (for example, /mnt/sda1/). Then:

Code:
scp test.txt admin@192.168.1.1:/mnt/sda1/
 
Well, after a lot of trial and error, I got it working with this:

Code:
scp test.txt admin@192.168.1.1:/tmp/mnt/Elements

Thanks for all your help Merlin, on this and for all you do.
 
If anyone has any further advice on this, I would appreciate it. I have enabled SSH on my AC68U router, and can ssh into it with no problem (using my private key and no password). However, when I try to scp to it, I get an "Invalid argument" error. HDD is USB(3) attached disk (formatted hfs+ btw). I have no other sharing setup (FTP/Samba etc), do I need to set that up as well? I can browse to the disk when I connect over SSH (by going to /tmp/mnt/Backup). And help greatly appreciated. Thanks!
 
If anyone has any further advice on this, I would appreciate it. I have enabled SSH on my AC68U router, and can ssh into it with no problem (using my private key and no password). However, when I try to scp to it, I get an "Invalid argument" error. HDD is USB(3) attached disk (formatted hfs+ btw). I have no other sharing setup (FTP/Samba etc), do I need to set that up as well? I can browse to the disk when I connect over SSH (by going to /tmp/mnt/Backup). And help greatly appreciated. Thanks!

What command are you using?

Can you run scp and increase the verbosity ("scp -v ...")? That will show you more info that will help you debug.

From my linux machine "scp file.txt admin@merlin:/tmp/mnt/storage" executed error-free. Like you, my Asus device is not running ftp, samba, nfs, etc.
 
What command are you using?

Can you run scp and increase the verbosity ("scp -v ...")? That will show you more info that will help you debug.

From my linux machine "scp file.txt admin@merlin:/tmp/mnt/storage" executed error-free. Like you, my Asus device is not running ftp, samba, nfs, etc.

Thanks for looking at this, I did just increase the verbosity, and here is what I got (edited out actual IPs and addresses):

root@myserver:~# scp -v /var/www/html/index.php myaccount@myrouteraddress:/tmp/mnt/Backup

Executing: program /usr/bin/ssh host myrouteraddress, user myaccount, command scp -v -t /tmp/mnt/Backup

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014

debug1: Reading configuration data /etc/ssh/ssh_config

debug1: /etc/ssh/ssh_config line 19: Applying options for *

debug1: Connecting to myrouteraddress [xxx.xxx.xxx.xxx] port 22.

debug1: Connection established.

debug1: permanently_set_uid: 0/0

debug1: identity file /root/.ssh/id_rsa type 1

debug1: identity file /root/.ssh/id_rsa-cert type -1

debug1: identity file /root/.ssh/id_dsa type -1

debug1: identity file /root/.ssh/id_dsa-cert type -1

debug1: identity file /root/.ssh/id_ecdsa type -1

debug1: identity file /root/.ssh/id_ecdsa-cert type -1

debug1: identity file /root/.ssh/id_ed25519 type -1

debug1: identity file /root/.ssh/id_ed25519-cert type -1

debug1: Enabling compatibility mode for protocol 2.0

debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6

debug1: Remote protocol version 2.0, remote software version dropbear_2014.66

debug1: no match: dropbear_2014.66

debug1: SSH2_MSG_KEXINIT sent

debug1: SSH2_MSG_KEXINIT received

debug1: kex: server->client aes128-ctr hmac-md5 none

debug1: kex: client->server aes128-ctr hmac-md5 none

debug1: sending SSH2_MSG_KEX_ECDH_INIT

debug1: expecting SSH2_MSG_KEX_ECDH_REPLY

debug1: Server host key: ECDSA xx:2f:xx:xx:xx:e7:f9:0e:e0:1c:xx:d4:cf:fc:xx:xx

debug1: Host 'myserver' is known and matches the ECDSA host key.

debug1: Found key in /root/.ssh/known_hosts:1

debug1: ssh_ecdsa_verify: signature correct

debug1: SSH2_MSG_NEWKEYS sent

debug1: expecting SSH2_MSG_NEWKEYS

debug1: SSH2_MSG_NEWKEYS received

debug1: SSH2_MSG_SERVICE_REQUEST sent

debug1: SSH2_MSG_SERVICE_ACCEPT received

debug1: Authentications that can continue: publickey

debug1: Next authentication method: publickey

debug1: Offering RSA public key: /root/.ssh/id_rsa

debug1: Server accepts key: pkalg ssh-rsa blen 279

debug1: key_parse_private2: missing begin marker

debug1: read PEM private key done: type RSA

debug1: Authentication succeeded (publickey).

Authenticated to myrouteraddress ([xxx.xxx.xxx.xxx]:22).

debug1: channel 0: new [client-session]

debug1: Entering interactive session.

debug1: Sending environment.

debug1: Sending env LANG = en_US.UTF-8

debug1: Sending command: scp -v -t /tmp/mnt/Backup

Sending file modes: C0644 418 index.php

Sink: C0644 418 index.php

scp: /tmp/mnt/Backup/index.php: Invalid argument

root@myserver:~# debug1: client_input_channel_req: channel 0 rtype exit-status reply 0

debug1: channel 0: free: client-session, nchannels 1

debug1: fd 0 clearing O_NONBLOCK

debug1: fd 1 clearing O_NONBLOCK

Transferred: sent 3376, received 1720 bytes, in 0.4 seconds

Bytes per second: sent 8429.0, received 4294.4

debug1: Exit status 1

...and then, nothing is actually transferred to the USB disk attached to the router :(
 
Are you sure dropbear has scp capabilities enabled?
 
Not at all, I assumed scp would work because ssh worked. How do I check/enable?

Dunno. :) I am as lost as you are now that "-v" showed nothing useful.


Have you checked the system logs? It should show dropbear-related info.
 
Dunno. :) I am as lost as you are now that "-v" showed nothing useful.


Have you checked the system logs? It should show dropbear-related info.

So, this is strange: I logged in via ssh, typed dropbear, which didn't do anything. Then I rebooted, and voila my files are transferring via scp. Not sure if it is due to:

1. issuing dropbear command?
2. simple reboot needed after hotplugging the external USB3 drive? (even though it was recognized without)
3. reboot needed for some other reason? (first connect from new machine/key, other)

Anyway, scp now works from my remote server. But rsync still won't :( (I get
sh: rsync: not found

rsync: connection unexpectedly closed (0 bytes received so far) [sender]

rsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.0])
 
Strange. You may have fubared something and the reboot fixed it. Unless you messed with jffs user-configs or nvram, a reboot will return you to the original firmware state, well... from a file-system perspective.

If you are sending files locally, you could use tar & netcat (nc) to pipe an arbitrary group of files & folders across a network. I love anything that uses netcat.
 
yeah, I did think that would be a good idea, so I went down the rabbit hole of installing entware, then rsync, and now rsync won't work because of this error:

rsync: This rsync lacks old-style --compress due to its external zlib. Try -zz.

And when I try to use -zz instead of -z it gives me the same error. It was working fine in optware, I should have left well enough alone...
 
Reboot? :)
 
UPDATE: I downloaded, compiled and installed a newer version of rsync on the source server and all is working as expected. There was no way entware would allow me to install an older version on the router, which is why I had to upgrade the source or go back to (supposedly) crappy optware.
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top