Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command line SSH refactor #488

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@
* [TLS auth](usingcurl/tls/auth.md)
* [TLS backends](usingcurl/tls/backends.md)
* [SSLKEYLOGFILE](usingcurl/tls/sslkeylogfile.md)
* [SCP and SFTP](usingcurl/scpsftp.md)
* [SCP and SFTP](usingcurl/ssh/README.md)
* [URLs](usingcurl/ssh/url.md)
* [Authentication](usingcurl/ssh/auth.md)
* [Known hosts](usingcurl/ssh/knownhosts.md)
* [Reading email](usingcurl/reademail.md)
* [Sending email](usingcurl/smtp.md)
* [DICT](usingcurl/dict.md)
Expand Down
20 changes: 10 additions & 10 deletions bookindex.md

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions cmdline/exitcode.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,8 @@ A basic Unix shell script could look like something like this:

51. The server's SSL/TLS certificate or SSH fingerprint failed verification.
curl can then not be sure of the server being who it claims to be. See the
[using TLS with curl](../usingcurl/tls.md) and
[using SCP and SFTP with curl](../usingcurl/scpsftp.md) sections for more
details.
[using TLS with curl](../usingcurl/tls.md) and [using SCP and SFTP with
curl](../usingcurl/ssh/) sections for more details.

52. The server did not reply anything, which in this context is considered an
error. When an HTTP(S) server responds to an HTTP(S) request, it always
Expand Down
2 changes: 1 addition & 1 deletion usingcurl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ conveniently as possible.
* [.netrc](netrc.md)
* [Proxies](proxies/)
* [TLS](tls.md)
* [SCP and SFTP](scpsftp.md)
* [SCP and SFTP](ssh/)
* [Reading email](reademail.md)
* [Sending email](smtp.md)
* [DICT](dict.md)
Expand Down
99 changes: 0 additions & 99 deletions usingcurl/scpsftp.md

This file was deleted.

19 changes: 19 additions & 0 deletions usingcurl/ssh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SCP and SFTP

curl supports the SCP and SFTP protocols if built with a prerequisite 3rd
party library: [libssh2](https://www.libssh2.org/),
[libssh](https://www.libssh.org/) or
[wolfSSH](https://www.wolfssl.com/products/wolfssh/).

SCP and SFTP are both protocols that are built on top of SSH, a secure and
encrypted data protocol that is similar to TLS but differs in a few important
ways. For example, SSH does not use certificates of any sort but instead it
uses public and private keys. Both SSH and TLS provide strong crypto and
secure transfers when used correctly.

The SCP protocol is generally considered to be the black sheep of the two
since it is not portable and usually only works between Unix systems.

* [URL](url.md)
* [Authentication](auth.md)
* [Known hosts](knownhosts.md)
26 changes: 26 additions & 0 deletions usingcurl/ssh/auth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Authentication

Authentication with curl against an SSH server (when you specify an SCP or
SFTP URL) is done like this:

1. curl connects to the server and learns which authentication methods that
this server offers
2. curl then tries the offered methods one by one until one works or they all
failed

curl attempts to use your public key as found in the `.ssh` subdirectory in
your home directory if the server offers public key authentication. When doing
so, you still need to tell curl which username to use on the server. For
example, the user 'john' lists the entries in his home directory on the remote
SFTP server called 'sftp.example.com':

curl -u john: sftp://sftp.example.com/

If curl cannot authenticate with the public key for any reason, it instead
attempts to use the username + password if the server allows it and the
credentials are passed on the command line.

For example, the same user from above has the password `RHvxC6wUA` on a remote
system and can download a file via SCP like this:

curl -u john:RHvxC6wUA -O scp://ssh.example.com/file.tar.gz
25 changes: 25 additions & 0 deletions usingcurl/ssh/knownhosts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Known hosts

A secure network client needs to make sure that the remote host is exactly the
host that it thinks it is communicating with. With TLS based protocols, it is
done by the client verifying the server's certificate.

With SSH protocols there are no server certificates, but instead each server
can provide its unique key. Unlike TLS, SSH has no certificate authorities or
anything so the client simply has to make sure that the host's key matches
what it already knows (via other means) it should look like.

The matching of keys is typically done using hashes of the key and the file
that the client stores the hashes for known servers is often called
`known_hosts` and is put in a dedicated SSH directory. On Linux systems that
is usually called `~/.ssh`.

When curl connects to a SFTP and SCP host, it makes sure that the host's key
hash is already present in the known hosts file or it denies continued
operation because it cannot trust that the server is the right one. Once the
correct hash exists in `known_hosts` curl can perform transfers.

To force curl to skip checking and obeying to the `known_hosts` file, you can
use the `-k / --insecure` command-line option. You must use this option with
extreme care since it makes it possible for man-in-the-middle attacks not to
be detected.
34 changes: 34 additions & 0 deletions usingcurl/ssh/url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# URLs

SFTP and SCP URLs are similar to other URLs and you download files using these
protocols the same as with others:

curl sftp://example.com/file.zip -u user

and:

curl scp://example.com/file.zip -u user

SFTP (but not SCP) supports getting a file listing back when the URL ends with
a trailing slash:

curl sftp://example.com/ -u user

Note that both these protocols work with "users" and you do not ask for a file
anonymously or with a standard generic name. Most systems require that users
authenticate, as outlined below.

When requesting a file from an SFTP or SCP URL, the file path given is
considered to be the absolute path on the remote server unless you
specifically ask for the path relative to the user's home directory. You do that by
making sure the path starts with `/~/`. This is quite the opposite to how FTP
URLs work and is a common cause for confusion among users.

For user `daniel` to transfer `todo.txt` from his home directory, it would
look similar to this:

curl sftp://example.com/~/todo.txt -u daniel

or for SCP

curl scp://example.com/~/todo.txt -u daniel:secret
Loading