0746.html 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Self-Hosted ACME (Automated Certificate Management Environment) Server with Step-CA on Linux</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="Self-Hosted ACME Server,Self-Hosted Let's Encrypt,Let's Encrypt Alternative,Home Lab,Home Lab Ideas,Install Guide,Self-Hosted,Self-Signed SSL,Self-Signed PKI,Self-Signed HTTPS,Self-Signed Certificate,Public Key Infrastructure,Public Key User Interface,SSL Certificates,Self-Signed,PKI,Linux,IT Security,HTTPS,Debian,Encryption,Certificates,Certificate Authority,Let's Encrypt,ACME,How To,Tutorial,i12bretro">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Self-Hosted ACME (Automated Certificate Management Environment) Server with Step-CA on Linux">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <meta name="revised" content="05/06/2022 12:46:52 PM" />
  12. <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
  13. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  14. <script type="text/javascript" src="includes/js/steps.js"></script>
  15. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="gridContainer">
  19. <div class="topMargin"></div>
  20. <div id="listName" class="topMargin">
  21. <h1>Self-Hosted ACME (Automated Certificate Management Environment) Server with Step-CA on Linux</h1>
  22. </div>
  23. <div></div>
  24. <div id="content">
  25. <h2>What is Step-CA?</h2>
  26. <blockquote><em>[Step-CA is] a private certificate authority (X.509 &amp; SSH) &amp; ACME server for secure automated certificate management, so you can use TLS everywhere &amp; SSO for SSH. -<a href="https://github.com/smallstep/certificates" target="_blank">https://github.com/smallstep/certificates</a></em></blockquote>
  27. <h2>Installing Step-CA and Step-CLI</h2>
  28. <ol>
  29. <li>Log into the Linux device</li>
  30. <li>Run the following commands in a terminal
  31. <div class="codeBlock"># update software repositories<br />
  32. sudo apt update<br />
  33. # install available software updates<br />
  34. sudo apt upgrade -y<br />
  35. # clean up downloaded apt files<br />
  36. sudo apt clean<br />
  37. # lookup latest steps-ca release URL<br />
  38. regex=&#39;&quot;browser_download_url&quot;: &quot;(https:\/\/github.com\/smallstep\/certificates\/releases\/download\/[^/]*\/step-ca_[^/]*amd64\.deb)&quot;&#39; &amp;&amp; response=$(curl -H &quot;Accept: application/vnd.github.v3+json&quot; https://api.github.com/repos/smallstep/certificates/releases/latest) &amp;&amp; [[ $response =~ $regex ]] &amp;&amp; downloadURL=&quot;${BASH_REMATCH[1]}&quot;<br />
  39. # download steps-ca server<br />
  40. wget -O ./steps-ca.deb $downloadURL<br />
  41. # install steps-ca server<br />
  42. sudo dpkg -i ./steps-ca.deb<br />
  43. # lookup latest steps-cli release URL<br />
  44. regex=&#39;&quot;browser_download_url&quot;: &quot;(https:\/\/github.com\/smallstep\/cli\/releases\/download\/[^/]*\/step-cli_[^/]*amd64\.deb)&quot;&#39; &amp;&amp; response=$(curl -H &quot;Accept: application/vnd.github.v3+json&quot; https://api.github.com/repos/smallstep/cli/releases/latest) &amp;&amp; [[ $response =~ $regex ]] &amp;&amp; downloadURL=&quot;${BASH_REMATCH[1]}&quot;<br />
  45. # download steps-cli client<br />
  46. wget -O ./steps-cli.deb $downloadURL<br />
  47. # install steps-cli client<br />
  48. sudo dpkg -i ./steps-cli.deb<br />
  49. # create the /etc/step-ca directory<br />
  50. sudo mkdir /etc/step-ca<br />
  51. # elevate to root user<br />
  52. sudo su<br />
  53. # set the step-ca path<br />
  54. export STEPPATH=/etc/step-ca<span style="display: none;"> </span></div>
  55. </li>
  56. </ol>
  57. <h2>Initialize A New Certificate Authority</h2>
  58. <ol>
  59. <li>Continue with the following commands in a terminal
  60. <div class="codeBlock"># initilize a CA<br />
  61. step ca init</div>
  62. </li>
  63. <li>Select standalone &gt; press Enter</li>
  64. <li>Enter a name for the PKI/Certificate Authority [ie i12bretro Certificate Authority] &gt; Press Enter</li>
  65. <li>Enter the IP address and/or DNS name of the Step-CA host [ie debian.i12bretro.local,192.168.0.57] &gt; Press Enter</li>
  66. <li>Enter the port for Step-CA to listen on [ie :8443] &gt; Press Enter</li>
  67. <li>Enter a first provisioner e-mail address [ie i12bretro@i12bretro.local] &gt; Press Enter</li>
  68. <li>Enter a password for the CA or leave it blank to have a password generated &gt; Press Enter</li>
  69. </ol>
  70. <h2>Installing Step-CA Service/Daemon</h2>
  71. <ol>
  72. <li>Continue with the following commands in a terminal
  73. <div class="codeBlock"># add ACME provisioner<br />
  74. step ca provisioner add acme --type ACME<br />
  75. # exit root shell<br />
  76. exit<br />
  77. # create password.txt, replace with the CA password<br />
  78. echo &#39;$YourCAPassword!!&#39; | sudo tee -a /etc/step-ca/password.txt &gt; /dev/null<br />
  79. # create step-ca user<br />
  80. sudo useradd --system --home /etc/step-ca --shell /bin/false step-ca<br />
  81. # set ownership of /etc/step-ca<br />
  82. sudo chown step-ca:step-ca /etc/step-ca -R<br />
  83. # limit permissions on the password.txt file<br />
  84. sudo chmod 400 /etc/step-ca/password.txt<br />
  85. # create step-ca log directory<br />
  86. sudo mkdir /var/log/step-ca -p<br />
  87. # set ownership of step-ca logs<br />
  88. sudo chown step-ca:step-ca /var/log/step-ca -R<br />
  89. # edit the ca configuration<br />
  90. sudo nano /etc/step-ca/config/ca.json<span style="display: none;"> </span></div>
  91. </li>
  92. <li>By default, step-ca certificates are only valid for 24 hours. To adjust this, paste the following inside each of the provisioners sections of the ca.json configuration file and adjust the values as needed<span style="display: none;"> </span>
  93. <p>&quot;claims&quot;: {<br />
  94. &quot;maxTLSCertDuration&quot;:&quot;26280h&quot;,<br />
  95. &quot;defaultTLSCertDuration&quot;:&quot;8760h&quot;<br />
  96. },</p>
  97. </li>
  98. <li>Press CTRL+O, Enter, CTRL+X to write the changes and close nano</li>
  99. <li>Continue with the following commands in a terminal
  100. <div class="codeBlock"># create service file<br />
  101. sudo nano /etc/systemd/system/step-ca.service</div>
  102. </li>
  103. <li>Paste the following configuration into step-ca.service
  104. <p>[Unit]<br />
  105. Description=step-ca service<br />
  106. After=network.target<br />
  107. StartLimitIntervalSec=0</p>
  108. <p>[Service]<br />
  109. Type=simple<br />
  110. Restart=always<br />
  111. RestartSec=1<br />
  112. User=step-ca<br />
  113. Group=step-ca<br />
  114. Environment=STEPPATH=/etc/step-ca<br />
  115. ExecStart=/bin/sh -c &quot;/usr/bin/step-ca ${STEPPATH}/config/ca.json --password-file=${STEPPATH}/password.txt &gt;&gt; /var/log/step-ca/step-ca.log 2&gt;&amp;1&quot;</p>
  116. <p>[Install]<br />
  117. WantedBy=multi-user.target</p>
  118. </li>
  119. <li>Press CTRL+O, Enter, CTRL+X to write the changes and close nano</li>
  120. <li>Continue with the following commands to enable and start the service:
  121. <div class="codeBlock"># reload systemd services<br />
  122. sudo systemctl daemon-reload<br />
  123. # start step-ca service on boot and now<br />
  124. sudo systemctl enable step-ca --now</div>
  125. </li>
  126. </ol>
  127. <h2>Automating Certificate Requests</h2>
  128. <ol>
  129. <li>Log into the server needing to request a certificate</li>
  130. <li>Continue following commands in a terminal window
  131. <div class="codeBlock"># copy the step-ca root certificate to trusted certs<br />
  132. sudo cp /etc/step-ca/certs/root_ca.crt /usr/local/share/ca-certificates/<br />
  133. # copy the step-ca intermediate certificate to trusted certs<br />
  134. sudo cp /etc/step-ca/certs/intermediate_ca.crt /usr/local/share/ca-certificates/<br />
  135. # update ca certs<br />
  136. sudo update-ca-certificates<br />
  137. # remove apt version of certbot if installed<br />
  138. sudo apt remove certbot -y<br />
  139. # install snapd<br />
  140. sudo apt install snapd -y<br />
  141. # install snap core and update<br />
  142. sudo snap install core; sudo snap refresh core<br />
  143. # install certbot snap<br />
  144. sudo snap install --classic certbot<br />
  145. # create certbot symbolic link<br />
  146. sudo ln -s /snap/bin/certbot /usr/bin/certbot<br />
  147. # request the certificate<br />
  148. sudo REQUESTS_CA_BUNDLE=/etc/step-ca/certs/root_ca.crt certbot certonly --standalone -d &lt;%host%&gt; --server https://&lt;%step-ca-host%&gt;:&lt;%step-ca-port%&gt;/acme/acme/directory</div>
  149. </li>
  150. <li>When prompted, enter an email address and agree to the terms of service</li>
  151. <li>Choose whether to share your email and receive emails from certbot</li>
  152. <li>Certbot will output information regarding the location of the certificate files</li>
  153. </ol>
  154. <p>Sources: <a href="https://smallstep.com/docs/step-ca/installation" target="_blank">https://smallstep.com/docs/step-ca/installation</a><br />
  155. <a href="https://certbot.eff.org/instructions?ws=other&amp;os=debianbuster" target="_blank">https://certbot.eff.org/instructions?ws=other&amp;os=debianbuster</a><br />
  156. <a href="https://smallstep.com/docs/tutorials/acme-challenge/" target="_blank">https://smallstep.com/docs/tutorials/acme-challenge/</a></p> </div>
  157. </div>
  158. </body>
  159. </html>