Fault-Tolerant SFTP Scripting
linuxjournal.com
linuxjournal.com
The downside of lftp's mirror subsystem is that directory enumeration is slower than rsync as there is no corresponding daemon on the other end to assist with the local aspect of remote enumeration. It is just using SFTP commands to do all the work.
This is a benefit for things like mirroring http hosted file repos, as many do not offer rsync due to security or increased load of running a service. Lftp still does a good job on those.
What I have noticed reading comments online is that people who express satisfaction with or actively promote PowerShell (the name still cracks me up) are often the same people who expressly dislike using UNIX or are blissfully ignorant of the UNIX shell's existence. As such, it's possible they would not miss something like an exit status in $? because they never actually tried using it.
Leave $? as boolean, but add $¿ as integer.
But if you're dealing with a multi billion dollar company that says "no", then this guide could come in handy.
This would be more difficult to do with rsync. I'd also be concerned with the account getting a shell, even if the command= option is set in authorized_keys.
In both cases the client is acessing an ssh server and relying on mere config files to ensure that the ssh server launches something other than a shell.
However rsync is also it's own service that doesn't have to use ssh at all, meaning no possible risk of getting a shell. It can be chrooted both from within and without (it can manage chroots of shares, and it can be chrooted itself). And wire encryption could be layered on some other way. ssh is merely convenient.
It is:
Match Group sftponly
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no
(Open)rsync is not included in OpenSSH, and it likely never will be.There may be multiple approaches to implement the above configuration with either the older GPL or newer BSD implementation of rsync, and the capabilities between the two variants will differ, adding further complexity.
The established best practice is the above configuration, for these reasons.
It means it's possible for sshd to supply a shell if it's merely confused about the config. It doesn't matter how "established" the config is. You are looking at what the config is supposed to do and thinking that is all nice and bulletproof looking. But that nice config that says "user X only gets the sftp subsystem" goes right out the window if you merely confuse sshd that you are not "user X" or any of the other match conditions.
Rsyncd on the other hand, has no code in it to offer up a shell. It can't be tricked into doing something that it has no code for in the first place.
The only reason ssh is usually involved with rsync is simply that rsync is not encrypted, so you tunnel rsync over some other channel to add encryption to it, and ssh is the most handy. But that other channel can actually be anything. It doesn't have to be ssh, and it doesn't even have to be any other form of shell server. For instance you could run a direct rsyncd and access it via vpn or tls tunnel, where together the two parts get you encrypted rsync and neither component posesses any ability to launch a shell, no matter what happens with the configs and no mattet what exploits come along.
I actually jacked it into stunnel once, full details in that past post, which google remembers quite well:
https://news.ycombinator.com/item?id=19520422
Tinyssh also has no config file; if you want it to service sftp, it must be passed in argv at startup, so less confusion there.
And there are two rsyncs now, so you have to be specific about which one. You likely mean the original, and not this one (the same people who wrote this had a showstopper bug in their new mail server):
All the bad stuff about ftp is not present in sftp.
The SITE command is thankfully not implemented in sftp, and the commands that traverse the wire are not ASCII, so they are indeed very different.
Sftp also left behind the ASCII/binary mangling of line endings.
I think the "ftp must die" paper reveals many of the foibles of ftp.