Skip to content

Instantly share code, notes, and snippets.

@silkyland
Last active February 23, 2023 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silkyland/22259465c70537b0e91ce1eda79dd303 to your computer and use it in GitHub Desktop.
Save silkyland/22259465c70537b0e91ce1eda79dd303 to your computer and use it in GitHub Desktop.
[Solved] CertStorageError: expected /etc/letsencrypt/live/example.com/cert.pem to be a symlink

[Solved] CertStorageError: expected /etc/letsencrypt/live/example.com/cert.pem to be a symlink

  rm -rf /etc/letsencrypt/live/{yourdomain.com}
  rm -rf /etc/archive/{yourdomain.com}
  rm -rf /etc/renewal/{yourdomain.com}

and

  certbot certonly --webroot -w /home/www/path -d yourdomain.com

If you use webinoly just use

  site example.com -ssl=on 

Don't forget to turn off ssl before delete them

@websharik
Copy link

websharik commented Mar 1, 2021

I resolve this problem with my universal script:

#FixError CertStorageError: expected /etc/letsencrypt/live/example.com/cert.pem to be a symlink

letsencryptdir="."

while read -r domain ; do

	#get domain
	domain=$(echo "$domain" | cut -f3 -d'/')

	#check symlink
	link="${letsencryptdir}/live/${domain}/cert.pem"
	if [ -L ${link} ] && [ -e ${link} ] ; then #is symlink and valid
		echo "${domain}: ok!"
		continue
	else
		echo -e "\e[31m${domain}: fail! fixing...\e[0m"
	fi

	#get latest num from archive
	count=$(find ${letsencryptdir}/archive/${domain} -type f -name 'cert*.pem' -printf x | wc -c)

	#recreate symlinks
	rm -f ${letsencryptdir}/live/$domain/*.pem
	ln -s ../../archive/${domain}/cert${count}.pem ${letsencryptdir}/live/${domain}/cert.pem
	ln -s ../../archive/${domain}/chain${count}.pem ${letsencryptdir}/live/${domain}/chain.pem
	ln -s ../../archive/${domain}/fullchain${count}.pem ${letsencryptdir}/live/${domain}/fullchain.pem
	ln -s ../../archive/${domain}/privkey${count}.pem ${letsencryptdir}/live/${domain}/privkey.pem

done < <(ls -d ${letsencryptdir}/live/*/)

@andyexeter
Copy link

@websharik Thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment