SSH & Certificate
when generating a new client keypair, I only have to copy the public key to my certificate signing machine (one copy) rather than every host I plan to log into (many copies). This more than makes up for the minor certificate configuration necessary on new clients. - HN
# Certificate
self signing CA + custom Authority for localhost on a specific server
# Generate your own Certificate Authority
You create your own trusted certificate authority, then use it to sign a separate certificate for localhost. Firefox trusts the CA, and therefore trusts the server certificate it signed.
mkdir -p ~/home-lab/certs
cd ~/home-lab/certs
# Create the CA private key
openssl genrsa -out home-lab-ca.key 4096
chmod 600 home-lab-ca.key # This is the most sensitive file. Keep it private and preferably make a secure backup.
Generate CA certificate
openssl req -x509 -new -nodes \
-key home-lab-ca.key \
-sha256 \
-days 3650 \
-out homelab-ca.crt \
-subj "/CN=My Home Lab Local CA" \
-addext "basicConstraints=critical,CA:TRUE" \
-addext "keyUsage=critical,keyCertSign,cRLSign" \
-addext "subjectKeyIdentifier=hash"
You now have:
- home-lab-ca.key: private CA key.
- homelab-ca.crt: public CA certificate.
- The CA certificate is the one you will import into Firefox. (setting / Advanced / Import)
# Generate Code Server certificate
create a separate private key for Code Server
openssl genrsa -out codeserver.key 2048
chmod 600 codeserver.key
Create a certificate signing request
openssl req -new \
-key codeserver.key \
-out codeserver.csr \
-subj "/CN=localhost"
Create an extension file:
cat > codeserver.ext <<EOF
basicConstraints=critical,CA:FALSE
keyUsage=critical,digitalSignature,keyEncipherment
extendedKeyUsage=serverAuth
subjectAltName=DNS:localhost,IP:127.0.0.1
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer
EOF
Sign the Code Server certificate using your CA:
openssl x509 -req \
-in codeserver.csr \
-CA homelab-ca.crt \
-CAkey home-lab-ca.key \
-CAcreateserial \
-out codeserver.crt \
-days 825 \
-sha256 \
-extfile codeserver.ext
You now have two separate certificate pairs:
| File | Purpose |
|---|---|
home-lab-ca.key |
Private CA key |
homelab-ca.crt |
CA certificate imported into Firefox |
codeserver.key |
Code Server private key |
codeserver.crt |
Code Server HTTPS certificate |
Important: Code Server uses codeserver.crt and codeserver.key, not the CA certificate and key.
Once the server certificate has been signed, you can move the CA private key to secure offline storage. Code Server does not need it at runtime.
# CodeServer Setup ⮺
~/.config/code-server/config.yaml
cert: /etc/ssl/certs/code-server.crt
cert-key: /etc/ssl/private/code-server.key
With permission
sudo chown root:root /etc/ssl/certs/code-server.crt
sudo chmod 644 /etc/ssl/certs/code-server.crt
sudo chown root:yves /etc/ssl/private/code-server.key
sudo chmod 640 /etc/ssl/private/code-server.key
Check access
sudo -u yves test -r /etc/ssl/certs/code-server.crt && echo "Certificate OK"
sudo -u yves test -r /etc/ssl/private/code-server.key && echo "Private key OK"
And then restart codeserver
sudo systemctl restart code-server@yves
# see also
- Parallel Reconstruction of Lawful TLS Wiretapping - TLS CA issuance & validation