0

I'm trying to append a certificate to a remote server's certificates file, using the folliwing command

openssl s_client -connect host:port | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | minikube ssh 'sudo su - && cat >> /etc/ssl/certs/ca-certificates.crt'

However, it seems that the remote host tries to evaluate the lines of text, rather than appending them to the remote file, leading to the following error mesages:

-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

How can I prevent the lines from being evaluated and just have them added to the remote file? Thanks!

  • 1
    I've no idea what minikube is but this is how I'd do it: openssl s_client -connect remote_server:443 </dev/null | sed -n '/-BEGIN CERTIFICATE/,/-END CERTIFICATE-/p' | ssh user@hostname 'tee -a /etc/ssl/certs/ca-certificates.crt'. – Valentin Bajrami Mar 2 '17 at 11:59
  • Thanks! "minikube ssh" is something like an alias for ssh user@minikube, in which minikube is the hostname. This approach with the standard ssh command keeps yielding the same errors unfortunately.. – dnikolos Mar 2 '17 at 14:46
  • sudo su - starts a subshell that reads its input as shell commands. Why are you trying to use the certificate file as commands? It looks like it was intended to be the input to the cat command, but that doesn't run until after sudo su - finishes. – Barmar Mar 2 '17 at 15:57
2

You're feeding the certificate as input to the sudo su - commands, so it's trying to execute it as shell commands. What you really want to do is run the cat command with 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"'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.