分类 电脑 下的文章

用 grml-live 制作 debian stable 的 iso 急救盘

需求:grml 当前官方可下载的版本是基于 debian 12/sid 构建的,如需 stable 的,怎么做呢?

尝试:

  1. 下载 grml64-full 的 iso 文件,因为里边有 grml-live 的命令
  2. 用 grml64-full 启动机子
  3. grml-live -s stable -c GRMLBASE,GRML_SMALL,AMD64 -o /srv/grml-live # 执行这条命令,就可以用 debian stable 来构建新的 iso 急救盘了
  4. 如需在 grub 菜单中添加内核启动的参数,例如设置静态IP,可添加形如:ip=144.172.126.97::144.172.126.1:255.255.255.0 这样的内容

参考:https://grml.org/grml-live/#deploy-on-debian

为 debian 系统所在的 / 分区调整大小 - e2fsck - resize2fs - 急救系统

需求:主机商安装的debian系统,默认绝大多数空间分配给了 / 分区,如 1.5TB。现在需要将 / 分区调整为 50GB。

步骤:

  1. 将机子从急救系统引导,即不挂载使用原硬盘上的分区
  2. e2fsck -f /dev/sda4 # 假设 /dev/sda4 是 debian 系统所在的 / 分区,先进行文件系统检查
  3. resize2fs /dev/sda4 50G # 压缩文件系统到50G
  4. cfdisk /dev/sda # 再通过cfdisk将 /dev/sda4 的分区调整到50G
  5. 退出急救系统,从硬盘的debian启动,检测是否调整分区成功

调整debian linux 根分区大小

批量添加用户 - iredmail - bash脚本

需求:自动生成用户名和密码,使用 iredmail 的脚本导入。
尝试:

#!/bin/bash
#For Loop to Read Three-expression

rm -rf /tmp/users.txt
rm -rf /tmp/users.sql

for ((i=1; i<=3; i++))
do
# echo "$i"
USER=$(strings /dev/urandom |tr -dc a-z0-9 | head -c8)
PWD=$(strings /dev/urandom |tr -dc a-z0-9 | head -c8)
DOMAIN="lan.anqun.org"

# echo $USER $PWD
# echo $USER '($PWD)'
echo $USER@$DOMAIN $PWD >> /tmp/users.txt
bash create_mail_user_SQL.sh $USER@$DOMAIN $PWD >> /tmp/users.sql
done

参考:

使用 curl 批量向 iredmail 提交新邮箱用户和密码

需求:iredmail 免费版没有 api,除了官方带的工具外,有没其它方法可以批量创建账号呢?

尝试:可以使用 curl 来提交表单,用脚本循环提交。

##
# Configurations.
##

read -p "请输入iredmain管理台的登录网址URL,如 https://mail.anqun.org/iredadmin/login: " login_url
read -p "请输入iredmail的创建用户网址URL,如 https://mail.anqun.org/iredadmin/create/user: " create_url
read -p "请输入邮局的管理员用户名,如 postmaster@lan.anqun.org: " username
read -p "请输入邮局的管理员用密码: " password

read -p "请输入要添加用户的域名,如 lan.anqun.org: " domainname
read -p "请输入要添加用户的个数,如 100: " number

rm iredmail-users.txt
rm tmpcs.txt
rm cookie

# Path to temporary file which will store your cookie data.
cookie_path=cookie

action_url="$create_url/$domainname"

##
# Logic. Most likely you shouldn't change here anything.
##

curl -i -b $cookie_path -c $cookie_path -d "username=$username&password=$password" "$login_url"

curl -i -b $cookie_path -c $cookie_path -o tmpcs.txt --request GET "$action_url"

csrf_token=$(grep -oP '(?<=<input type="hidden" name="csrf_token" value=")[^"]*' tmpcs.txt)


for ((i=1; i<=$number; i++))
    do
        mailuser=$(strings /dev/urandom |tr -dc a-z0-9 | head -c8)
        mailpasswd=$(strings /dev/urandom |tr -dc a-z0-9 | head -c8)
        echo $mailuser@$domainname  $mailpasswd >> iredmail-users.txt

        data="csrf_token=$csrf_token&domainName=$domainname&username=$mailuser&newpw=$mailpasswd&confirmpw=$mailpasswd&cn=&preferredLanguage=en_US&mailQuota=1024&submit_add_user=Add"
        curl -i --cookie cookie --data "${data}" "$action_url"
done

参考:https://www.drupal.org/node/2045751

为 magento 网站后台启用双因素身份验证登录 - 谷歌身份验证器 - Two-Factor Authentication - google authenticator

需求:magento 2.4 以上版本默认为网站后台启用双因素身份验证登录,假如主机不支持smtp发信,怎么办呢?

尝试:

  1. bin/magento config:set twofactorauth/general/force_providers google # 设置使用谷歌验证器
  2. bin/magento config:set twofactorauth/google/otp_window 60 # 设置验证码有效期一分钟
  3. bin/magento security:tfa:google:set-secret liujia NJUGMZZUPFSGEZDHBI====== # 为 liujia 用户设置 NJUGMZZUPFSGEZDHBI====== 密钥;可在linux里使用 echo jhfg4ydbdg | base32 的命令来生成密钥
  4. 在谷歌浏览器里,安装“身份验证器”的扩展。添加新项,手工输入标识和密钥
  5. 在 magento 里登录,会提示输入由谷歌身份验证器生成的动态验证码,六位数字

首次登录,会提示需按邮件内容启用2fa
图1:首次登录,会提示需按邮件内容启用2fa

手工输入密钥后,谷歌身份验证器会动态生成验证码
图2:手工输入密钥后,谷歌身份验证器会动态生成验证码

登录网站后台时,会提示输入动态验证码
图3:登录网站后台时,会提示输入动态验证码

参考: