Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL for SFTP with private key authentication

Tags:

curl

sftp

I need to upload files by SFTP from a PHP script. I think cURL is probably the way, as I have this available on the server.

Has anyone got an example of how to use cURL for SFTP using identity key authentication?

-- EDIT --

I've just noticed that HTTP PUT might be an alternative, but how secure it that?

like image 301
Owen Avatar asked Jul 14 '10 21:07

Owen


People also ask

How do you pass a private key in curl command?

To authenticate with a private key and certificate using curl, you will need to provide the --key and --cert options to your request. The private key must be decrypted in plain text. The provided certificate must contain the corresponding public key.

How do I pass a private key using SFTP?

Select Open Connection Select SFTP (SSH File Transfer Protocol) for the connection type. Enter server, port (22), username. You can skip password - it will use the SSH key. For SSH Private Key, select Choose... and find the save location of your file.

Does curl work with SFTP?

curl supports the SCP and SFTP protocols if built with a prerequisite 3rd party library: libssh2, libssh or wolfSSH.

Does SFTP require private key?

Some SFTP servers require both an SSH key and password for additional authentication. Anyone who tries to login with the username or password (or both) but doesn't have the correct private/public key match will be denied access to the server, regardless of whether they try to brute-force it.


1 Answers

curl -u <username>: --key ~/.ssh/id_rsa --pubkey ~/.ssh/id_rsa.pub sftp://<remote_host>/<remote_path>

HTTP is unsecured, so any data you send during PUT (e.g. a password or the files you are uploading) could be snooped and read in plain text. Depending on your application, this may or may not be a concern for you.

like image 117
idontevenseethecode Avatar answered Sep 16 '22 14:09

idontevenseethecode