如何从 curl(git-ftp)和 FileZilla 连接到 vsftpd?

如何从 curl(git-ftp)和 FileZilla 连接到 vsftpd?

下列的教程我设法向服务器添加 FTPS 连接。

按照教程中的第 6 步操作:

  • 6.1 生成证书

    $ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem

  • 6.2 添加证书/etc/vsftpd.conf

    rsa_cert_file=/etc/ssl/private/vsftpd.pem

    rsa_private_key_file=/etc/ssl/private/vsftpd.pem

它适用于 FileZilla,但使用 curl 似乎我无法重复使用相同的证书,我从服务器下载了证书文件并像这样使用它

$ curl -v --cert ~/.ssh/vsftpd.pem --user MYUSER:PASSWORD ftp://SERVER-IP
*   Trying SERVER-IP...
* TCP_NODELAY set
* Connected to SERVER-IP (SERVER-IP) port 21 (#0)
< 220 (vsFTPd 3.0.3)
> USER MYUSER
< 530 Non-anonymous sessions must use encryption.
* Access denied: 530
* Closing connection 0
curl: (67) Access denied: 530

使用 FTPS

$ curl -v --cert ~/.ssh/vsftpd.pem --user MYUSER:PASSWORD ftps://SERVER-IP
*   Trying SERVER-IP...
* TCP_NODELAY set
* Connection failed
* connect to SERVER-IP port 990 failed: Connection refused
* Failed to connect to SERVER-IP port 990: Connection refused
* Closing connection 0
curl: (7) Failed to connect to SERVER-IP port 990: Connection refused

我如何对 FileZilla 和 curl 使用相同的证书(因为 git-ftp 使用 curl)通过 FTPS 上传文件?

更新

添加参数--ftp-ssl

*   Trying SERVER-IP...
* TCP_NODELAY set
* Connected to SERVER-IP (SERVER-IP) port 21 (#0)
< 220 (vsFTPd 3.0.3)
> AUTH SSL
< 234 Proceed with negotiation.
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /usr/local/etc/openssl/cert.pem
  CApath: /usr/local/etc/openssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS alert, unknown CA (560):
* SSL certificate problem: self signed certificate
* Closing connection 0
curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

答案1

curls 参数--cert用于提供客户端身份验证证书。只要您不使用客户端证书进行身份验证,就不需要它。

要使用 ftps,请使用--ftp-ssl参数。

答案2

由于 macOS 上的 curl 使用 Keychain Access 应用程序上的数据库,因此说明与 Linux 所需的说明不同,因此我记录了说明这里


在 macOS 客户端上使用 git-ftp,在 Linux 服务器上使用 vsftpd

生成 SSL 证书和密钥

$ openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout ~/.ssh/vsftpd.key -out ~/.ssh/vsftpd.crt

将生成的证书添加到 Keychain Access 应用中

$ security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/.ssh/vsftpd.crt

将证书和密钥上传到服务器并将文件复制到/etc/ssl/private/

按照描述的步骤这里,在步骤 6 中使用已经生成的证书,而不是生成新的证书

rsa_cert_file=/etc/ssl/private/vsftpd.crt
rsa_private_key_file=/etc/ssl/private/vsftpd.key

在服务器上运行 vsftpd 后,安装 git-ftp

$ brew install git-ftp

添加使用 ftpes 协议的服务器设置

$ git config git-ftp.url "ftpes://<SERVER-IP>/path/to/repository/"
$ git config git-ftp.user "<FTP-USER>"
$ git config git-ftp.password "<FTP-PASSWORD>"
$ git config git-ftp.cacert "~/.ssh/vsftpd.crt"

初始化 git-ftp,此时存储库将在初始化过程中上传

$ git ftp init -v

在存储库中添加其他提交后,将更改推送到 ftp 存储库

$ git ftp push -v

相关内容