Ubuntu Mydomain.pem : Permission denied

sslUbuntu

I have a five files in my Webserver(Nginx) folder :

  1. cert_www.Mydomain.com.crt
  2. prv_www.Mydomain.com.key
  3. rootca_www.Mydomain.com.crt
  4. subca1_www.Mydomain.com.crt
  5. subca2_www.Mydomain.com.crt

i want to combine the crt files. but my commands not working. i'm using cat command. please see the below command.

ubuntu@ip:/etc/nginx/ssl$ sudo cat cert_www.Mydomain.com.crt subca1_www.Mydomain.com.crt rootca_www.Mydomain.com.crt > www.Mydomain.com.pem
-bash: www.Mydomain.com.pem: Permission denied

I don't understand, not really sure what's going wrong.

Best Answer

This is happening because the shell redirection applies in your unprivileged shell; it doesn't get the benefit of the sudo.

Just get a regular root shell (run sudo -i) and then run the command again. There are trickier ways of doing it (such as piping through sudo tee) but it's not worth the hassle for a simple interactive session.