0746.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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="08/11/2023 04:10:24 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. # install prerequisites<br />
  36. sudo apt install curl wget -y<br />
  37. # clean up downloaded apt files<br />
  38. sudo apt clean<br />
  39. # lookup latest steps-ca release URL<br />
  40. 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 />
  41. # download steps-ca server<br />
  42. wget -O ./steps-ca.deb $downloadURL<br />
  43. # install steps-ca server<br />
  44. sudo dpkg -i ./steps-ca.deb<br />
  45. # lookup latest steps-cli release URL<br />
  46. 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;
  47. &amp;&amp; downloadURL=&quot;${BASH_REMATCH[1]}&quot;<br />
  48. # download steps-cli client<br />
  49. wget -O ./steps-cli.deb $downloadURL<br />
  50. # install steps-cli client<br />
  51. sudo dpkg -i ./steps-cli.deb<br />
  52. # create the /etc/step-ca directory<br />
  53. sudo mkdir /etc/step-ca<br />
  54. # elevate to root user<br />
  55. sudo su<br />
  56. # set the step-ca path<br />
  57. export STEPPATH=/etc/step-ca<span style="display: none;"> </span></div>
  58. </li>
  59. </ol>
  60. <h2>Initialize A New Certificate Authority</h2>
  61. <ol>
  62. <li>Continue with the following commands in a terminal
  63. <div class="codeBlock"># initilize a CA<br />
  64. step ca init</div>
  65. </li>
  66. <li>Select standalone &gt; press Enter</li>
  67. <li>Enter a name for the PKI/Certificate Authority [ie i12bretro Certificate Authority] &gt; Press Enter</li>
  68. <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>
  69. <li>Enter the port for Step-CA to listen on [ie :8443] &gt; Press Enter</li>
  70. <li>Enter a first provisioner e-mail address [ie i12bretro@i12bretro.local] &gt; Press Enter</li>
  71. <li>Enter a password for the CA or leave it blank to have a password generated &gt; Press Enter</li>
  72. </ol>
  73. <h2>Installing Step-CA Service/Daemon</h2>
  74. <ol>
  75. <li>Continue with the following commands in a terminal
  76. <div class="codeBlock"># add ACME provisioner<br />
  77. step ca provisioner add acme --type ACME<br />
  78. # exit root shell<br />
  79. exit<br />
  80. # create password.txt, replace with the CA password<br />
  81. echo &#39;$YourCAPassword!!&#39; | sudo tee -a /etc/step-ca/password.txt &gt; /dev/null<br />
  82. # create step-ca user<br />
  83. sudo useradd --system --home /etc/step-ca --shell /bin/false step-ca<br />
  84. # set ownership of /etc/step-ca<br />
  85. sudo chown step-ca:step-ca /etc/step-ca -R<br />
  86. # limit permissions on the password.txt file<br />
  87. sudo chmod 400 /etc/step-ca/password.txt<br />
  88. # create step-ca log directory<br />
  89. sudo mkdir /var/log/step-ca -p<br />
  90. # set ownership of step-ca logs<br />
  91. sudo chown step-ca:step-ca /var/log/step-ca -R<br />
  92. # edit the ca configuration<br />
  93. sudo nano /etc/step-ca/config/ca.json<span style="display: none;"> </span></div>
  94. </li>
  95. <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>
  96. <p>&quot;claims&quot;: {<br />
  97. &quot;maxTLSCertDuration&quot;:&quot;26280h&quot;,<br />
  98. &quot;defaultTLSCertDuration&quot;:&quot;8760h&quot;<br />
  99. },</p>
  100. </li>
  101. <li>Press CTRL+O, Enter, CTRL+X to write the changes and close nano</li>
  102. <li>Continue with the following commands in a terminal
  103. <div class="codeBlock"># create service file<br />
  104. sudo nano /etc/systemd/system/step-ca.service</div>
  105. </li>
  106. <li>Paste the following configuration into step-ca.service
  107. <p>[Unit]<br />
  108. Description=step-ca service<br />
  109. After=network.target<br />
  110. StartLimitIntervalSec=0</p>
  111. <p>[Service]<br />
  112. Type=simple<br />
  113. Restart=always<br />
  114. RestartSec=1<br />
  115. User=step-ca<br />
  116. Group=step-ca<br />
  117. Environment=STEPPATH=/etc/step-ca<br />
  118. 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>
  119. <p>[Install]<br />
  120. WantedBy=multi-user.target</p>
  121. </li>
  122. <li>Press CTRL+O, Enter, CTRL+X to write the changes and close nano</li>
  123. <li>Continue with the following commands to enable and start the service:
  124. <div class="codeBlock"># reload systemd services<br />
  125. sudo systemctl daemon-reload<br />
  126. # start step-ca service on boot and now<br />
  127. sudo systemctl enable step-ca --now</div>
  128. </li>
  129. </ol>
  130. <h2>Automating Certificate Requests</h2>
  131. <ol>
  132. <li>Log into the server needing to request a certificate</li>
  133. <li>Continue following commands in a terminal window
  134. <div class="codeBlock"># copy the step-ca root certificate to trusted certs<br />
  135. sudo cp /etc/step-ca/certs/root_ca.crt /usr/local/share/ca-certificates/<br />
  136. # copy the step-ca intermediate certificate to trusted certs<br />
  137. sudo cp /etc/step-ca/certs/intermediate_ca.crt /usr/local/share/ca-certificates/<br />
  138. # update ca certs<br />
  139. sudo update-ca-certificates<br />
  140. # remove apt version of certbot if installed<br />
  141. sudo apt remove certbot -y<br />
  142. # install snapd<br />
  143. sudo apt install snapd -y<br />
  144. # install snap core and update<br />
  145. sudo snap install core; sudo snap refresh core<br />
  146. # install certbot snap<br />
  147. sudo snap install --classic certbot<br />
  148. # create certbot symbolic link<br />
  149. sudo ln -s /snap/bin/certbot /usr/bin/certbot<br />
  150. # request the certificate<br />
  151. 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>
  152. </li>
  153. <li>When prompted, enter an email address and agree to the terms of service</li>
  154. <li>Choose whether to share your email and receive emails from certbot</li>
  155. <li>Certbot will output information regarding the location of the certificate files</li>
  156. </ol>
  157. <p>Sources: <a href="https://smallstep.com/docs/step-ca/installation" target="_blank">https://smallstep.com/docs/step-ca/installation</a><br />
  158. <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 />
  159. <a href="https://smallstep.com/docs/tutorials/acme-challenge/" target="_blank">https://smallstep.com/docs/tutorials/acme-challenge/</a></p> </div>
  160. </div>
  161. </body>
  162. </html>