我在网上找到了一篇关于如何从命令行中获取Gnome Keyring密码的帖子(如何在终端中获取密钥环中的密码以供脚本使用?),并发现secret-tool是解决方法。使用secret-tool可以很好地存储密码,但我似乎无法弄清楚如何查找使用seahorse存储的现有密码,这正是我真正希望做到的。我不知道需要使用哪些属性和值来查询它们,而且man手册对这些可能是什么也没有明确说明。
Collection: Login
Item: Test Password
Secret: Tr0ub4dor&3
Key: xdg:schema
Value: org.gnome.keyring.Note
Item: secret-tool item
Secret: s3cret-t00l
Key: my key
Value: my value
Key: xdg:schema
Value: org.freedesktop.Secret.Generic
Item: Unlock password for: cueball@xkcd.com
Secret: correct horse battery staple
Key: unique
Value: ssh-store:/home/cueball/.ssh/id_rsa
Key: xdg:schema
Value: org.freedesktop.Secret.Generic
Item: Network secret for GenericSSID/802-1x/password
Secret: S3cureW1f1Passw0rd
Key: setting-name
Value: 802-1x
Key: connection-uuid
Value: 6a762552-04b3-cd05-45ba-586688e0a029
Key: xdg:schema
Value: org.freedesktop.NetworkManager.Connection
Key: setting-key
Value: password
secret-tool store --label="secret-tool item" "my key" "my value"
添加的项目,然后在提示中输入"s3cret-t00l"。
3. 用于自动解锁gnome keyring中的ssh密钥的密码。它是通过命令行中的ssh-add添加的,然后在首次使用时选中了"登录时自动解锁此密钥"框。
4. 通过在NetworkManager连接编辑器中选择"仅为此用户存储密码"来添加的wifi网络密码。
正如您所见,使用Seahorse添加到钥匙链中的密码具有"xdg:schema"和"org.gnome.keyring.Note"的键值对。您可以使用secret-tool search --all xdg:schema org.gnome.keyring.Note
列出所有这些密码。
在路径 /org/freedesktop/secrets/collection/login/13 下没有此类秘密项目
。事实上,当我尝试使用GNOME Seahorse时,也会得到完全相同的错误。看起来libsecret存在问题,或者可能某些发行版已对libsecret进行了加固。人们正在讨论有关钥匙链问题的内容,请参考https://gitlab.gnome.org/GNOME/seahorse/-/issues/157和https://gitlab.gnome.org/GNOME/gnome-keyring/-/issues/91。 - Mitch McMabers$ secret-tool store --label=DomainPassword user sjohnson domain some.domain
Password: thisismypa$$w0rd
$ secret-tool lookup user sjohnson domain some.domain
thisismypa$$w0rd
我现在已经测试过了,可以使用以下参数恢复我的密码:
secret-tool lookup server "ownCloud"
outFile="keyRingExport.csv"
# Get all secrets from keyring
items=`secret-tool search --all xdg:schema org.gnome.keyring.Note`
# Clean exsisiting file
echo "">"$outFile"
currentPath="none"
currentLabel="none"
currentSecret="none"
while IFS= read -r line; do
if [[ $line == "["* ]]; then
# Trim Path
currentPath=${line/\/org\/freedesktop\/secrets\/collection\//""}
fi
if [[ $line == "label"* ]]; then
# Trim lable
currentLabel=${line/label = /""}
# CSV escape
currentLabel="\"${currentLabel//\"/"\"\""}\""
fi
if [[ $line == "secret"* ]]; then
# Trim secret
currentSecret=${line/secret = /""}
# CSV escape
currentSecret="\"${currentSecret//\"/"\"\""}\""
# write to file
echo "$currentPath,$currentLabel,$currentSecret" >> "$outFile"
# reset current variables
currentPath="none"
currentLabel="none"
currentSecret="none"
fi
done <<< "$items"