The escaping behavior is incorrect in that it only escapes the first apostrophe, which is only made necessary because commands are execute through `bash`. Since `bash` is not guaranteed to be installed (sad, but true), and since this represents unexpected behavior, I've pared this down to the simplest thing that could possibly work.
The presence of ENV['SSH_AUTH_SOCK'] is necessary but not sufficient for
ssh-agent support (e.g. no agent may be listening on the socket; the
listening agent may be SSH2-compatible and hence currently unsupported)
so it is better to delegate this decision to Net::SSH.