SSH straight to specific directory

Post your questions and help other users.

Moderator: Martin

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

SSH straight to specific directory

Post by digitalstone » 22 Nov 2018 14:12

With the Execute SSH Command action, i've been trying to transfer this file for the last few hours to my server now, along the likes of:

Command

Code: Select all

cat > \Download\test.png
Input File

Code: Select all

/storage/emulated/0/test.png
But the only actual successful file transfer has been the root folder.
I'm probably limited by my command knowledge.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
beelze
Posts: 46
Joined: 04 Nov 2018 16:45

Re: SSH straight to specific directory

Post by beelze » 22 Nov 2018 14:42

Not quite understand what exactly you're trying to do. Transfer (copy)?

cat > file redirecting cat' output to file. So you're trying to store stdin to file. More, path separator is /, not \.

And what about input file?

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: SSH straight to specific directory

Post by digitalstone » 22 Nov 2018 15:03

Yes i'm trying to transfer a file from my phone to a server through SSH (within the same network).

I saw inside the help of some other action to use this command.
scp also has been a failed attempt.
But again, my command knowledge isn't all that.

External path seperator is "\". Or do you mean this path is yet to be interpreted by the server, which makes it an internal path from there?
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
beelze
Posts: 46
Joined: 04 Nov 2018 16:45

Re: SSH straight to specific directory

Post by beelze » 22 Nov 2018 15:44

You can't transfer file using ssh command. You need scp or (more universal and versatile, rsync)

Testing from adb shell, scp works as expected (minimal working example):

Code: Select all

scp -o StrictHostKeyChecking=no -i /path/to/privkey.rsa /path/to/source/file myuser@myhost:/path/to/destination
Of course, myhost have corresponding pubkey in .ssh/authorized_keys (or wherever points AuthorizedKeysFile in sshd_config)
You can use Execute [root] command to invoke scp like above.

Please explain about «External path separator», still no idea about.

User avatar
beelze
Posts: 46
Joined: 04 Nov 2018 16:45

Re: SSH straight to specific directory

Post by beelze » 22 Nov 2018 15:51

upd: it is not a good idea to connect via ssh using KbdInteractiveAuthentication/PasswordAuthentication (entering/providing password). It more secure, easy and convenient to use PubkeyAuthentication (expected to be turned on by default on any ssh server).

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: SSH straight to specific directory

Post by digitalstone » 22 Nov 2018 16:32

Using pubkeys was on my to-do list so thanks for reviving that ;)
Better trying this out both at once since they're going hand in hand.
I have not ever worked with, nor created pubkey before so this might take longer than expected. Or maybe it's easy, i don't know.

There is just no port number inside your command.
I take that it is still necessary somewhere?

And is the "StrictHostKeyChecking=no" safe at all?

With "external path separators" is just meant the backslashes you use inside a path on any terminal outside (external) the local host.
Example: \\servername\folder\file.ext
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
beelze
Posts: 46
Joined: 04 Nov 2018 16:45

Re: SSH straight to specific directory

Post by beelze » 22 Nov 2018 17:55

1. I'm using standard ssh port (22) everywhere, because there is no real security improvement in using different port. There is no need to explicitly declare port 22.
2. PasswordAuth designed to be interactive (most ssh-related tools not supported password-providing command line options, nor even reading password from stdin, because is it very insecure), so you can face real problems trying to build command line providing password. Yes, you can use *expect utils, but for what? It is very simple to generate keypair and use it.
3. Use either StrictHostKeyChecking=no or maintain known_hosts file on client side. But, if server resides in the same network, I guess there is no much sense in checking server key.
4. \\servername\folder\file.ext is a windows path, isn't it? So ssh server is a Windows host? Why ssh then?

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: SSH straight to specific directory

Post by digitalstone » 22 Nov 2018 18:45

Port 22 could easily be done indeed. But just having that 1 extra number to figure out the port at all makes it, in my book at least, a tiny bit more 'secure' than having just the standard 22.
I'm aware there are 2 camps on that whole debate, so you know which one i'm clinging onto now.

But that explains it then. Other than my server (Qnap) and phone, i'm a Windows user.
It did not even occur to me that there are no backslashes inside linux paths because i almost never have to type in those paths (... i just didn't pay attention).

StrictHostKeyChecking=no would then make sense yes. The server is just always the same Qnap machine in the house.

Thanks. I appreciate your time.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
beelze
Posts: 46
Joined: 04 Nov 2018 16:45

Re: SSH straight to specific directory

Post by beelze » 22 Nov 2018 19:18

It is no harm to use -P 22 in scp command line. But, there are 50+ another ssh options, consider man scp and man ssh_config ;-)

But I got another idea. If file transfer is the one and only use of ssh, why not to use something more simple and secure? E.g. Dropbox Upload File action? Dropbox is not secure? Well, you can deploy something like owncloud or seafile on your server[s], there are android clients for both.

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: SSH straight to specific directory

Post by digitalstone » 22 Nov 2018 21:24

Owncloud and Seafile both look like promising software. When i'm further with setting up my stuff, i will definitely dig into them.

For manual phone-to-server transfer i use ES File Explorer which i bought years ago and have no problem with.
But the whole point for now is to automatically transferring file(s) to the server. I didn't bought it for nothing, and project files, media, sensitive files and such (which take way to long to transfer through internet where i live btw) are surely not going to live somewhere on some server(s) :cry:
I mean, i'm a guy who sees a problem in using the default SSH port :lol:

Btw, i have PuTTy and WinSCP installed.
Can do some things with them if necessary.
But again, that's just manual control.
I'm more about automation to focus on other tasks.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

Post Reply