-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Export letsencrypt certificates #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I would also like to be able to link to the cert folder based on the site name. Its useful for npm to handle renewal for certs for services other than web. I can see where the numbered folders map to but having site name folders would ease configuration. Also concerned numbering may change, breaking cert paths. |
Same here. I use NPM on my Synology. I need to import the generate certificate for use it with Drive Client (desktop app). |
First of all great project, really top-notch! This feature would be helpful, as I'm using wildcard certs which I wish I could export from the UI. Meanwhile, anyone using the docker image can copy the files from the container to the host with the following commands:
Replace NPM_CONTAINER_ID with your container id, find it by running docker ps Example: This will copy the certs from the container to the current working directory. |
If you have many sites and many ssl certs, it's difficult to discern which npm-[0-9]* folder contains the certificates you want. I iterate through the nom folders and run |
Duplicate of #404 |
+1, would love this too ! ;) Thank you ^^ |
I solved this with a python script to copy out the certs to named folders. Not very well tested. |
I would also like to see this. I need to copy the SSL certificates over to mailcows SSL folder. |
Hi all,
certificates numbers found in hope this can be useful |
I use NPM on my Unaraid server. #!/usr/bin/python3
import os
from pathlib import Path
from paramiko import SSHClient
from scp import SCPClient
from paramiko import AutoAddPolicy, RSAKey, SSHClient
proxy_hosts_dir = '/mnt/user/appdata/Nginx-Proxy-Manager-Official/data/nginx/proxy_host'
archive_dir = '/mnt/user/appdata/Nginx-Proxy-Manager-Official/letsencrypt/archive'
target_host = 'dns.host'
host_file = ''
for filename in os.listdir(proxy_hosts_dir):
file = os.path.join(proxy_hosts_dir, filename)
if os.path.isfile(file) and filename.endswith('.conf'):
with open(file) as f:
if target_host in f.read():
host_file = file
archive_id = int(Path(host_file).stem) + 1
archive_path = archive_dir + '/npm-' + str(archive_id)
max_cert = int(1)
for certfilename in os.listdir(archive_path):
certfile = os.path.join(archive_path, certfilename)
index = int(''.join(filter(lambda i: i.isdigit(), certfilename)))
if index > max_cert:
max_cert = index
fullchain = archive_path + '/fullchain' + str(max_cert) + '.pem'
privkey = archive_path + '/privkey' + str(max_cert) + '.pem'
client = SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect('192.168.1.1', username='unraid')
sftp = client.open_sftp()
sftp.put(fullchain, '/home/unraid/letsencrypt/' + target_host + '.fullchain.pem')
sftp.put(privkey, '/home/unraid/letsencrypt/' + target_host + '.privkey.pem')
sftp.close() |
@balya Thanks for your suggestion! I run Prosody as a chat server (not on the NGINX Proxy Manager machine) and also need to transfer the certs to Prosody. I found the numbering scheme you use above not reliable, especially when making NPM configuration changes. So I opted for actually reading the relevant parts of NPM’s #!/usr/bin/python3
import re
import os
from pathlib import Path
from paramiko import SSHClient
from scp import SCPClient
from paramiko import AutoAddPolicy, RSAKey, SSHClient
proxy_hosts_dir = '/home/admin/npm/data/nginx/proxy_host'
archive_dir = '/home/admin/npm/letsencrypt/live'
target_host = 'chat.mydomain.net'
host_file = ''
for filename in os.listdir(proxy_hosts_dir):
file = os.path.join(proxy_hosts_dir, filename)
if os.path.isfile(file) and filename.endswith('.conf'):
with open(file) as f:
content = f.read();
m = re.search(r'server_name\s+(.*);', content)
if m:
s = m.group(1).split()
basename = ('_').join(s).replace("*", "x")
if target_host in s:
f = re.search(r'ssl_certificate\s+/etc/letsencrypt/live(.*);', content)
if f:
fullchain = archive_dir + f.group(1)
p = re.search(r'ssl_certificate_key\s+/etc/letsencrypt/live(.*);', content)
if p:
privkey = archive_dir + p.group(1)
client = SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect('prosody', username='myusername')
sftp = client.open_sftp()
sftp.put(fullchain, '/home/myusername/certs/' + target_host + '.fullchain.pem')
sftp.put(privkey, '/home/myusername/certs/' + target_host + '.privkey.pem')
sftp.close() This script I run via root’s crontab on the NPM machine every night at 3:00 a.m. like so: 0 3 * * * /home/admin/bin/ssl-chat.py And on the Prosody machine, since it can’t reload correctly, at 3:10 a.m., also via root’s crontab: 10 3 * * * prosodyctl --root cert import chat.mydomain.net /home/myusername/certs/ Works well so far. Maybe this can help others, too. |
If i use your script and edit the paths and username etc. i get this Error: No idea, how i can solve it |
I tried to write a sample script to export certificates from Nginx Proxy Manager for use with mailcow mail server. You can adapt it to use with any application. https://github.com/LazyGatto/npm-cert-export |
This is my take on it; one VM with NPM container (192.168.0.44)- another VM with a ZNC bouncer from where the bash script is run in a cron job from the root user, every 90 days. First execution is on the 25th of September 2023. If you go to SSL Certificates in NPM, you can see which #number the certificate it is listed as ( Cron: I am running the ZNC bouncer as a regular user (
|
Hello,
Can you add a link to download each certificate generated by letsencrypt? It's usefull to put it in adguard for exemple DNS-over-TLS.
privkey.pem
: the private key for your certificate.fullchain.pem
: the certificate file used in most server software.Thes files are located in letsencrypt/live/npm-XX/
Thank you in advance.
The text was updated successfully, but these errors were encountered: