[Share Experiences] 分享一种加强磁盘加密方法用于防范窃贼和黑客,补充2025/2/13
Tofloor
poster avatar
LinuxhzxWuLiao@outlook.com
deepin
2024-04-22 01:49
Author

这个脚本是生成字母和数字的,要生成所有可打印字符要把tr -dc '[:alnum:]'改成tr -dc '[:print:]'。我之前的脚本有问题,怎么没人告诉我,我自己发现的。就是迭代那里出现了无意义迭代。这次我想了点办法。之前的迭代是计算了设定次数,但是没有指定怎样迭代,这次简单用前一个密码奇数和后一个密码偶数组合来重复指定次数以此迭代。错了大半年我自己发现了。

#!/bin/bash
# 设置迭代次数
iterations=800
# 设置密码长度
password_length=20
# Step 1: Generate initial password using /dev/urandom
initial_password=$(head -c $password_length < /dev/urandom | tr -dc '[:alnum:]')
while [ ${#initial_password} -lt $password_length ]; do
    initial_password+=$(head -c $((password_length - ${#initial_password})) < /dev/urandom | tr -dc '[:alnum:]')
done
echo "初始密码:$initial_password"
# Step 2: Iterate to process the password 800 times
current_password=$initial_password
for ((i=1; i<=$iterations; i++)); do
    # 从 /dev/urandom 中读取新的一段随机数据
    random_data=$(head -c $password_length < /dev/urandom | tr -dc '[:alnum:]')
    while [ ${#random_data} -lt $password_length ]; do
        random_data+=$(head -c $((password_length - ${#random_data})) < /dev/urandom | tr -dc '[:alnum:]')
    done
  
    # 将当前密码和随机数据按奇偶位置组合
    new_password=""
    for ((j=0; j<$password_length; j++)); do
        if (( i % 2 == 0 )); then
            # 偶数次迭代,处理偶数位置
            if (( j % 2 == 0 )); then
                new_password+="${current_password:j:1}"
            else
                new_password+="${random_data:j:1}"
            fi
        else
            # 奇数次迭代,处理奇数位置
            if (( j % 2 != 0 )); then
                new_password+="${current_password:j:1}"
            else
                new_password+="${random_data:j:1}"
            fi
        fi
    done
  
    # 更新当前密码
    current_password=$new_password
done
echo "迭代后的密码:$current_password"

修改磁盘密码

lsblk -f

sudo cryptsetup luksChangeKey /dev/sd

其中sd可以开始sda也可以是sdb,用lsblk -f查询“卢卡斯”加密方式是哪个区。

还有就是那个迭代加密的脚本有时候会闪退,在后面加两行这个可以解决:
read -n 1
echo 继续运行

还有就是最好搭配bios密码使用,尤其有的安装双系统,bios密码可以很好的隔离卢卡斯和bitlocker。

还有一种办法是将密码不显示,用于在有摄像头或者人多的时候。

sudo apt-get install xsel

安装一个xsel,据说这是一个剪贴板共享的工具。

#!/bin/bash
# 生成初始随机密码
random_password=$(cat /dev/random | tr -dc [:print:] | fold -w 1 | head -n 4)
iterations=80
# 迭代生成新的密码,并将结果重定向到 /dev/null 以避免显示在终端上
for ((i=1; i<=$iterations; i++)); do
    random_password=$(echo -n "$random_password" | tr -dc [:print:])
done > /dev/null
# 定义保存密码的文件路径
file_path="/home/你的用户名/Desktop/password.txt"
# 将最终生成的密码保存到文件中
echo "迭代后的密码:$random_password" > "$file_path"
# 将密码复制到剪贴板
echo -n "$random_password" | xsel --clipboard
echo "密码已成功保存到 $file_path 并复制到剪贴板"

这是可以消失密码的bash。其中有一段是输出到.txt,那是因为在摄像头之下是无法安全查看密码的,只能在方便的时候查看txt文档记忆密码。第一段的fold -w 1 | head -n 4是可以修改截取的位数和截取的次数。这个脚本有一个小缺点,在剪贴板里的和在.txt里密码的都要及时清空。

有的人在窗边使用电脑,也可能会被摄像头捕捉到在键盘上输入密码,我个人在家里使用两副键盘,一副随意打字,一副藏着,用来输入密码。简而言之,保护密码,是使用高端Linux的先决条件之一。

第二种在摄像头和高密集人流的地方创建密码的方式,就是像这样↓↓↓

截图_选择区域_20241110220614.png

将密码在自己的脑子里解密成图片,然后根据图片输入密码,要这昂这样做需要一个先决条件,就是将密码最大位数调整到很大,这一行 random_password=$(cat /dev/random | tr -dc [:print:] | fold -w 1 | head -n 4) ,然后在多达几百位数的密码里筛选出4到16位作为密码,不过输入密码的时候依然需要复制粘贴才能保证安全,或者确保没人的地方输入。外人是看不出这些图片代表的字符的。

已知|{}“‘是无法写入密码的,如果不小心改成了含有|{}“‘,必须使用

lsblk -f

sudo cryptsetup luksChangeKey /dev/sd改回来,或者不要了

Reply Favorite View the author
All Replies
jjcui8595
deepin
Resources Team Moderator
2024-04-22 05:56
#1

like

Reply View the author
乾豫恒益
deepin
2024-04-22 11:35
#2

这个想法可以有,而且很实用,不知道用起来感觉如何?

如果真的经得住现实考验,可以大大的推广,因为感觉比指纹型的要靠谱,市面上的指纹的,都假的很,浪费了不少钱。

Reply View the author
乾豫恒益
deepin
2024-04-22 11:35
#3

收藏了

Reply View the author
库罗靡靡
deepin
2024-04-22 13:40
#4

openssl rand -base64 100

Reply View the author
LinuxhzxWuLiao@outlook.com
deepin
2024-10-19 22:28
#5
It has been deleted!
LinuxhzxWuLiao@outlook.com
deepin
2024-10-27 00:15
#6
It has been deleted!
LinuxhzxWuLiao@outlook.com
deepin
2024-11-10 22:25
#7
It has been deleted!
LinuxhzxWuLiao@outlook.com
deepin
2025-02-13 00:51
#8
It has been deleted!
LinuxhzxWuLiao@outlook.com
deepin
2025-02-13 21:15
#9

补充2025/2/13

Reply View the author