AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-1780395

boernsen's questions

Martin Hope
boernsen
Asked: 2025-02-20 20:30:24 +0800 CST

如何使用密钥文件通过 GUI 挂载 LUKS 加密的 USB?

  • 7

我在 Kubuntu 24.04 上用 cryptsetup 加密了一个外部 USB,同时使用了密码和密钥文件,并在 crypttab 中添加了相应的条目,但通过 GUI 安装时仍要求我输入密码。我该如何解决这个问题?

该驱动器使用以下命令加密:

# Preconditions:
# - USB is available as /dev/sda
# - Folder ~/.keyfiles exists
sudo cryptsetup luksFormat /dev/sda
sudo dd if=/dev/urandom of=~/.keyfiles/setup_32g.dat bs=512 count=294
sudo chmod 0400 ~/.keyfiles/setup_32g.dat
sudo chown root:root ~/.keyfiles/setup_32g.dat
sudo cryptsetup luksAddKey /dev/sda ~/.keyfiles/setup_32g.dat
sudo cryptsetup config /dev/sda --label sandisk_32g
sudo cryptsetup luksOpen /dev/sda sandisk_32g
sudo mkfs.ext4 /dev/mapper/sandisk_32g
sudo e2label /dev/mapper/sandisk_32g sandisk_32g
sudo mount /dev/mapper/sandisk_32g /media/$USER/sandisk_32g
sudo chmod 777 /media/$USER/sandisk_32g/.
sudo umount /media/$USER/sandisk_32g

在此之后,我得到了一个密码(keyslot 0)和一个密钥文件~/.keyfiles/setup_32g.dat(keyslot 1)。luksDump 显示:

$ sudo cryptsetup luksDump /dev/sda
LUKS header information
Version:        2
Epoch:          5
Metadata area:  16384 [bytes]
Keyslots area:  16744448 [bytes]
UUID:           172ea93c-7383-44da-8255-ce7d46856dc8
Label:          sandisk_32g
Subsystem:      (no subsystem)
Flags:          (no flags)

Data segments:
  0: crypt
        offset: 16777216 [bytes]
        length: (whole device)
        cipher: aes-xts-plain64
        sector: 512 [bytes]

Keyslots:
  0: luks2
        Key:        512 bits
        Priority:   normal
        Cipher:     aes-xts-plain64
        Cipher key: 512 bits
        PBKDF:      argon2id
        Time cost:  6
        Memory:     1048576
        Threads:    4
        Salt:       d6 0f b7 bc 68 c5 fc 65 14 56 16 b7 3f e8 f2 f6 
                    91 eb d6 ff bf b8 6d eb de bb e9 59 2f 65 35 be 
        AF stripes: 4000
        AF hash:    sha256
        Area offset:32768 [bytes]
        Area length:258048 [bytes]
        Digest ID:  0
  1: luks2
        Key:        512 bits
        Priority:   normal
        Cipher:     aes-xts-plain64
        Cipher key: 512 bits
        PBKDF:      argon2id
        Time cost:  6
        Memory:     1048576
        Threads:    4
        Salt:       ea 01 89 dd 26 ea 45 3b c5 20 90 c9 01 d9 9d 65 
                    3e 56 df e4 28 b4 81 ce ea e0 6e ae f4 0b c1 50 
        AF stripes: 4000
        AF hash:    sha256
        Area offset:290816 [bytes]
        Area length:258048 [bytes]
        Digest ID:  0
Tokens:
Digests:
  0: pbkdf2
        Hash:       sha256
        Iterations: 260321
        Salt:       b9 cf bc 7b da 79 0d a3 5a d8 e2 ea 45 32 c1 7a 
                    75 18 a6 2e 66 28 7c 49 c3 10 99 e8 84 05 b2 2f 
        Digest:     b6 7b 7d 94 78 19 41 6c 2a 6c b4 9c e9 e5 47 26 
                    cb ee 19 1d 95 7c d2 d1 97 f6 1f 77 ae 63 38 59

密钥文件具有以下权限:

-r--------  1 root root 150528 Dez 29 16:16 setup_32g.dat

之后,我在 crypttab 中添加了以下条目:

sandisk_32g  UUID=<removed>  /home/<myname>/.keyfiles/setup_32g.dat luks,noauto

到目前为止,我还没有在 fstab 中添加任何相关条目。

我可以不用任何密码运行sudo cryptdisks_start sandisk_32g(假设我已经拥有 sudo 权限)并且驱动器在文件管理器(KDE dolphin)中可用,因此我认为密钥文件使用正确。

但是,当我尝试从文件管理器 (KDE dolphin) 或任务栏中的“磁盘和设备”图标直接访问驱动器时(即无需cryptdisks_start先调用),系统意外提示我输入密码。如果我输入密码,它会正确打开。

我怎样才能让 GUI 安装过程使用来自 crypttab 的密钥文件而不是提示输入密码?


尝试:密钥文件权限

起初,我怀疑密钥文件缺少权限,但即使给它 777 也没有任何改变。

尝试:fstab

/dev/mapper/sandisk_32g /media/<myname>/sandisk_32g auto   noatime,users,nofail  0  0

或者

/dev/mapper/sandisk_32g  /media/<myname>/sandisk_32g  ext4  noatime,users,nofail,x-systemd.device-timeout=100ms,x-systemd.automount,x-systemd.idle-timeout=20min  0  0

如果我将上述条目之一添加到 fstab,则行为不一致且令人讨厌。连接 USB 驱动器后,每次在 KDE dolphin 文件管理器中第一次尝试时仍会要求我输入密码。有时当我取消对话框并再次访问驱动器时,它会打开而没有任何其他提示(因此使用密钥文件!)。但有时它不起作用,密码对话框会一直显示。此外,任务栏中弹出的“安装和打开”选项总是要求输入密码。当我尝试通过“磁盘和驱动器”任务栏图标卸载驱动器时,由于缺少卸载权限,系统会要求我输入管理员密码。通过 KDE dolphin 卸载有时似乎有效,但它在任务栏中一直显示为已安装,其中“安全删除”按钮似乎不再响应,所以我永远无法确定现在拔下是否安全。

尝试:日志分析

需要此处建议!

我希望使用sudo journalctl --since "1min ago"或找到任何相关内容sudo dmesg,但没有找到。

如果有人能告诉我更多相关日志我将非常感激!

解决方法

有趣的是,无论我使用任务栏还是 KDE dolphin,只要我输入密码,一切都会顺利进行,包括卸载权限。我想知道为什么会有区别?我可以激活 KDE 钱包,然后在出现提示时选择“记住密码”,并跳过整个密钥文件操作。当我测试这个时,它一直要求输入密码。此外,我想避免使用 KDE 钱包,并在 Keepass 中管理我的所有密码。

mount
  • 1 个回答
  • 131 Views
Martin Hope
boernsen
Asked: 2024-04-06 16:43:58 +0800 CST

使用 systemd 和 DNSOverTLS 时如何解决 DNS 泄漏问题

  • 6

2024 年 10 月 4 日更新:这不是真正的泄漏。请参阅下面 mpboden 接受的答案。

问题:

我在 Kubuntu Desktop 22.04 上连接到外部 wifi,并希望使用 DNSOverTLS 将 DNS 系统范围配置为 9.9.9.9 (quad9)。然而,在 dnsleaktest.com 上我仍然得到不同的 DNS。

我使用 Firefox 进行测试,并将“DNS over HTTPS”设置为“关闭”。

在https://on.quad9.net上我得到了预期的结果:YES, You ARE using quad9

在 dnsleaktest.com 上,我得到了未执行的结果:

dnsleaktest.com

这是我所做的:

在受影响 wifi 的 NetworkManager 中,我禁用了 IPv6 并将 IPv4 设置为“自动”(仅限地址),并放置一个空列表作为 DNS 服务器。终端中的配置结果为:

$ nmcli device
DEVICE        TYPE      STATE         CONNECTION
wlo1          wifi      connected     TP-LINK_58DE
p2p-dev-wlo1  wifi-p2p  disconnected  --
lo            loopback  unmanaged     --

$ nmcli device show wlo1
GENERAL.DEVICE:                         wlo1
GENERAL.TYPE:                           wifi
GENERAL.HWADDR:                         xx:xx:xx:xx:xx:xx
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     TP-LINK_58DE
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/1
IP4.ADDRESS[1]:                         192.168.0.112/24
IP4.GATEWAY:                            192.168.0.1
IP4.ROUTE[1]:                           dst = 192.168.0.0/24, nh = 0.0.0.0, mt = 600
IP4.ROUTE[2]:                           dst = 0.0.0.0/0, nh = 192.168.0.1, mt = 600
IP4.ROUTE[3]:                           dst = 169.254.0.0/16, nh = 0.0.0.0, mt = 1000
IP6.GATEWAY:                            --

我这样配置了 /etc/systemd/resolved.conf (只有最后几行是相关的,但为了完整性/错误检查,我提供了完整的文件):

$ cat /etc/systemd/resolved.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it under the
#  terms of the GNU Lesser General Public License as published by the Free
#  Software Foundation; either version 2.1 of the License, or (at your option)
#  any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the resolved.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# Use 'systemd-analyze cat-config systemd/resolved.conf' to display the full config.
#
# See resolved.conf(5) for details.

[Resolve]
# Some examples of DNS servers which may be used for DNS= and FallbackDNS=:
# Cloudflare: 1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
# Google:     8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google 2001:4860:4860::8844#dns.google
# Quad9:      9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
#DNS=
#FallbackDNS=
#Domains=
#DNSSEC=no
#DNSOverTLS=no
#MulticastDNS=no
#LLMNR=no
#Cache=no-negative
#CacheFromLocalhost=no
#DNSStubListener=yes
#DNSStubListenerExtra=
#ReadEtcHosts=yes
#ResolveUnicastSingleLabel=no
DNS=9.9.9.9#dns.quad9.net
FallbackDNS=9.9.9.9#dns.quad9.net
Domains=~.
DNSSEC=yes
DNSOverTLS=yes

在sudo systemctl restart systemd-resolved和之后sudo systemctl restart NetworkManager,这是生成的配置(整个输出粘贴在此处):

$ resolvectl status
Global
           Protocols: -LLMNR -mDNS +DNSOverTLS DNSSEC=yes/supported
    resolv.conf mode: foreign
  Current DNS Server: 9.9.9.9#dns.quad9.net
         DNS Servers: 9.9.9.9#dns.quad9.net
Fallback DNS Servers: 9.9.9.9#dns.quad9.net
          DNS Domain: ~.

Link 2 (wlo1)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS +DNSOverTLS DNSSEC=yes/supported

在基本测试中它似乎有效:

$ resolvectl query archlinux.com
archlinux.com: 3.64.163.50                     -- link: wlo1

-- Information acquired via protocol DNS in 1.1292s.
-- Data is authenticated: no; Data was acquired via local or encrypted transport: yes
-- Data from: cache network

$ dig archlinux.com

; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> archlinux.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60948
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;archlinux.com.                 IN      A

;; ANSWER SECTION:
archlinux.com.          7200    IN      A       3.64.163.50

;; Query time: 331 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Sat Apr 06 09:30:08 CEST 2024
;; MSG SIZE  rcvd: 58


$ ss -tuna | grep :853
tcp   TIME-WAIT 0      0           192.168.0.112:48420        9.9.9.9:853
tcp   ESTAB     0      0           192.168.0.112:49032        9.9.9.9:853

剩下的问题是:为什么我在 dnsleaktest.com 上得到不同的 DNS?

我尝试过的一些事情:

  • sudo resolvectl flush-caches
  • sudo resolvconf -u
  • 仅将 9.9.9.9 放入 NetworkManager 中的 IPv4 DNS 服务器列表中
  • 仅将 127.0.0.53 放入 NetworkManager 中的 IPv4 DNS 服务器列表中
  • 添加到和dns=none的 [main] 部分/etc/NetworkManager/NetworkManager.conf/etc/NetworkManager/conf.d/90-dns-none.conf
  • sudo systemctl restart systemd-resolved
  • sudo systemctl restart NetworkManager
  • 重启
  • 遵循本指南,该指南使用更简单的配置:https://www.ubuntubuzz.com/2022/04/enable-browsing-with-dns-over-tls-dot-on-ubuntu-made-easy.html
  • 遵循这个答案:https://askubuntu.com/a/1069429/1780395,即
cd /etc/
mv resolv.conf resolv.conf-old
ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
  • sudo dpkg-reconfigure resolvconf。这导致:

在此输入图像描述

$ ls -la /etc/resolv.conf 
lrwxrwxrwx 1 root root 29 Apr  8 09:10 /etc/resolv.conf -> ../run/resolvconf/resolv.conf

$ cat /etc/resolv.conf 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 127.0.0.53

还没有什么帮助。你能帮我解决这个问题吗?

networking
  • 1 个回答
  • 103 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve