gpt4 book ai didi

bash - 无人值守的 GPG 命令脚本在 GPG 命令处挂起

转载 作者:行者123 更新时间:2023-11-29 09:26:07 27 4
gpt4 key购买 nike

我想为一个 atm 创建一个自动 GnuPG key 生成脚本,尽管他们运行 ubuntu,但不习惯使用 CLI。此外,其他人管理他们的计算机,使其保持最新状态并处于良好的运行状态,因此他们也没有 root/sudo 访问权限。而且我真的很想尝试并尽可能避免通过电话进行说明......在那里的次数太多了,以至于不知道 PITA 会是什么样子!

因此,我大量借鉴了我在 gnupg.org 论坛上找到的示例(我想?)但是,无论在 3 或 4 分钟内产生多少鼠标事件,一旦运行 gpg --gen-key --batch 命令,它似乎就没有做任何事情。顺便说一句,所有 echo 语句只是指示脚本进度的临时方法,距离 atm 不是很远。

#!/bin/bash

# First run give your server some work, otherwise gpg won't be able to generator random bytes.
#sudo rngd -r /dev/urandom
#no sudo so:
echo -e "\nYou need to begin moving your mouse continuously and in random patterns for as long as it takes to generate a new key. This could take a minute or two, so be patient and just keep moving the mouse.\n"

echo -e "\ngpg --gen-key --batch\n"
gpg --batch --gen-key

%echo Generating a default key
Key-Type: default
Key-Length: 2048
Subkey-Type: default
Name-Real: Firstname Lastname
Name-Comment: No comment
Name-Email: user@domain.com
Expire-Date: 0
Passphrase: abcde
%pubring foo.pub
%secring foo.sec
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done

# kill the rngd task.
#sudo service rng-tools stop


echo -e "\ngpg -k\n"
gpg -k

# get key id for newly created passkey
echo -e "\nkId=$(gpg -k Firstname|grep pub|sed -r 's/^pub[ ]*2048R\/([A-Z0-9]{8,})[ ]*.*$/\1/')\n" #; echo "\$kId: ${kId}"
kId=$(gpg -k Firstname|grep pub|sed -r 's/^pub[ ]*2048R\/([A-Z0-9]{8,})[ ]*.*$/\1/') ; echo -e "\n\$kId: ${kId}\n"

# set key as the default key (if desired) by entering this line in your ~/.bashrc
echo -e "\nexport GPGKEY=$kId\n"
export GPGKEY="$kId"

# restart the gpg-agent and source your .bashrc again
echo -e "\nkillall -q gpg-agent\n"
killall -q gpg-agent
eval $(gpg-agent --daemon)
source ~/.bashrc

#create revocation cert
echo -e "\ngpg --output revoke.asc --gen-revoke $GPGKEY\n"
gpg --output revoke.asc --gen-revoke $GPGKEY

# send public key to keyserver
echo -e "\ngpg --send-keys --keyserver keyserver.ubuntu.com $GPGKEY\n"
#gpg --send-keys --keyserver keyserver.ubuntu.com $GPGKEY

我想知道是否有人可以看到任何明显的问题或遗漏提供“gpg”所需的关键细节?

即使我使用 sudo rngd -r/dev/random 命令运行脚本,我也会得到同样的结果,我需要为目标用户绕过(无 sudo 访问权限)。

所以我想问题出在我想传递给 gpg 的关键参数中,但我已经将它们与手册页进行了交叉引用,但似乎无法找到问题所在。有趣的是 gpg 没有返回错误。

最佳答案

对于批量 key 生成,GnuPG 期望文件中的创建命令,与 GnuPG manual page on batch key generation 比较.

cat <<EOT >batch-cmds
%echo Generating a default key
Key-Type: default
Key-Length: 2048
Subkey-Type: default
Name-Real: Firstname Lastname
Name-Comment: No comment
Name-Email: user@domain.com
Expire-Date: 0
Passphrase: abcde
%pubring foo.pub
%secring foo.sec
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
EOT
gpg --batch --gen-key batch-cmds

考虑将密码存储在硬盘文件中的安全隐患。我不确定您是否也可以将内容直接通过管道传输到 GnuPG 而不是将它们存储到文件中。尝试这样的事情:

gpg --batch --gen-key <<EOT
%echo Generating a default key
Key-Type: default
Key-Length: 2048
Subkey-Type: default
Name-Real: Firstname Lastname
Name-Comment: No comment
Name-Email: user@domain.com
Expire-Date: 0
Passphrase: abcde
%pubring foo.pub
%secring foo.sec
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
EOT

关于bash - 无人值守的 GPG 命令脚本在 GPG 命令处挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23779810/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com