Posts in category “Linux”

Ubuntu主机生成兼容Android5证书并自动续期

English version

文言文,雅文也。余心向往之,故尝试以文言述此篇,若令君不悦,尚请原谅。

叙言

现代之网站开发,使用HTTPS协定,甚关键。Let's Encrypt所赐之SSL证书虽免费,然其证书链,不尽兼容旧安卓版本,如Android5。本文叙及生成兼容Android5证书之法,及自动续期之道。

第一步:安装Certbot及Nginx

先须确保汝主机上安装有Certbot及Nginx。

sudo apt-get update
sudo apt-get install certbot nginx

第二步:下载ISRG Root X1证书

自Let's Encrypt网站下载最新之ISRG Root X1证书,贮于指定之目录。

sudo wget -O /etc/letsencrypt/isrgrootx1.pem https://letsencrypt.org/certs/isrgrootx1.pem

第三步:编写自动化符

创一脚本名"update-certificates.sh",每当Certbot续证书后,自动生成兼容Android5证书链,并重新加载Nginx之配置。

#!/bin/bash

DOMAIN="yourdomain.com" 
CERT_DIR="/etc/letsencrypt/live/$DOMAIN"
FULLCHAIN="$CERT_DIR/fullchain.pem"
PRIVKEY="$CERT_DIR/privkey.pem"
ANDROID_FULLCHAIN="$CERT_DIR/fullchain-android.pem"
ISRG_ROOT="/etc/letsencrypt/isrgrootx1.pem"

# 生成兼容Android5证书链
sudo cat $FULLCHAIN $ISRG_ROOT | sudo tee $ANDROID_FULLCHAIN > /dev/null

# 重新加载Nginx之配置
sudo systemctl reload nginx

切记将DOMAIN替换为汝之实际域名,确保路径正确。

第四步:赐予脚本执行权

sudo chmod +x /path/to/update-certificates.sh

第五步:配置Certbot续订钩子

Certbot支持于续订证书后运行自定义钩子脚本。将上脚本配置为Certbot之"--deploy-hook"钩子。

编辑Certbot之续订配置文件(通常在/etc/letsencrypt/renewal/yourdomain.com.conf):

renew_hook = /path/to/update-certificates.sh

或使用Certbot之命令行选项配置:

sudo certbot renew --deploy-hook /path/to/update-certificates.sh

第六步:设置自动续订

Certbot默将配置一cron作业或systemd timer以自动续订证书。可通过以下命令确认:

sudo systemctl list-timers | grep certbot

若无自动续订任务,可手动添加一cron作业:

sudo crontab -e

于crontab文件中添加以下行,每日运行续订检查:

0 2 * * * /usr/bin/certbot renew --deploy-hook /path/to/update-certificates.sh

总结

经上述步骤,可确保使用Let's Encrypt所生之HTTPS证书兼容Android5,并实现证书之自动续订。如是,则无需每三月手动更新一次证书,大大简化了网站之维护工作。

Delete to beginning of current word in Bash

Instead of pressing backspace repeatedly, press ESC then Backspace.

Reference

Don't you want more? here's some

  • how to delete to the end of the line? Ctrl + k
  • how to delete to the beginning of the line? Ctrl + u
  • Simply move the cursor to the line of the beginning? Ctrl + a

Want a full list?

Here you are

ubuntu 22.04 audio output not working (dummy audio)

the following solution works for my old dell Chromebook

echo "options snd-hda-intel model=generic" | sudo tee -a /etc/modprobe.d/alsa-base.conf

A power off and then power on might be needed.

Running xUbuntu on a SDCard

Finally, I decided to install xUbuntu on a 256GB SDCard as the 16GB built-in emmc drive on a chromebook (Dell P22T) is too small for a desktop system.

Undoubtly, SDCard is slow and easier to be broken. So I took the following actions to the file system and hope they can help solve both issues:

  1. Turning off atime.

  2. Disabling the journal feature.

My New Productivity Hacks

Muscle Memory Makeover

Docker just streamlined Docker Compose by integrating it as a plugin. Great news, but it means us old hats need to retrain our fingers. Here's a quick fix for your .bashrc to keep things smooth:

alias docker-compose='docker compose'

MySQL in a Flash

As a programmer and Linux admin, I juggle multiple MySQL servers with different group suffixes. Typing --defaults-group-suffix every time was a drag. This handy bash function saves the day:

m() {
    if [ $# -eq 0 ]; then
        # If no arguments provided, run mysql directly
        mysql
    elif [[ "$1" == -* ]]; then
        # If first argument starts with -, pass all arguments directly to mysql
        mysql "$@"
    else
        # Otherwise, treat first argument as suffix
        local suffix=$1
        shift
        mysql --defaults-group-suffix=$suffix "$@"
    fi
}

Now, connecting to a database is as easy as:

m specific-suffix

This keeps your workflow concise and saves you precious keystrokes. Put them into you .bashrc or .zshrc now and let our life easier!