我正在尝试使用以下命令将证书附加到远程服务器的证书文件
openssl s_client -connect host:port | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | minikube ssh 'sudo su - && cat >> /etc/ssl/certs/ca-certificates.crt'
但是,远程主机似乎尝试评估文本行,而不是将它们附加到远程文件,从而导致以下错误消息:
-sh: line 1: -----BEGIN: command not found
-sh: line 2: MIIGETCCA/mgAwIBAgIQBNtwjkSfT+QGafgAnqb9JDANBgkqhkiG9w0BAQsFADBK: No such file or directory
-sh: line 3: MQswCQYDVQQGEwJOTDEdMBsGA1UEChMUS29uaW5rbGlqa2UgS1BOIE4uVi4xHDAa: command not found
-sh: line 4: BgNVBAMTE0tQTiBOLlYuIFByaXZhdGUgQ0EwHhcNMTYwNzI4MDAwMDAwWhcNMTkw: command not found
-sh: line 5: NzI4MjM1OTU5WjCBhDELMAkGA1UEBhMCTkwxFTATBgNVBAgMDFp1aWQgSG9sbGFu: command not found
.
.
.
-sh: line 35: -----END: command not found
如何防止对这些行进行评估并将它们添加到远程文件中?谢谢!
答案1
您将证书作为sudo su -
命令的输入,因此它尝试将其作为 shell 命令执行。你真正想做的是运行cat
命令sudo
:
openssl s_client -connect host:port |
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' |
minikube ssh 'sudo bash -c "cat >> /etc/ssl/certs/ca-certificates.crt"'