Linux用户帐户中是否存在秘密数据?

发布于 2024-08-22 00:44:47 字数 232 浏览 6 评论 0原文

我希望我的应用程序(PHP,但这不重要)将一些数据存储在共享存储库(APC 用户缓存,但同样不相关)中。为了防止用户读取彼此的数据,我想对每个用户进行加密。

我可以让用户在应用程序的配置文件中指定密钥,但我宁愿自动生成它,这样用户就不必费心了。

为此,我需要系统上的一段数据(几乎)永远不会改变并且只能由当前用户读取。然后我可以对其进行散列或其他操作来生成密钥。 Linux 系统上的默认用户帐户中是否存在类似的内容?

I want my application (PHP, but that shouldn't matter) to store some data in a shared repository (the APC user cache, but again irrelevant). To prevent users from reading eachother's data I'd like to encrypt it per user.

I could have the user specify the key in his configuration file for the application, but I'd rather generate it automatically so the user doesn't have to bother.

For this I would need a piece of data on the system that (almost) never changes and is only readable by the current user. I can then hash that, or something, to generate the key. Does something like that exist in a default user account on a Linux system?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猥︴琐丶欲为 2024-08-29 00:44:47

如果您将密钥文件的权限设置为 0600,并将 ~/.yourApp 目录的权限设置为 0700,则可以将密钥存储在 ~/.yourApp 中。

当然,您依赖于那些无法/不愿意使用 root 访问权限来访问其他用户的密钥文件的人。如果这是一个问题,您将需要使用某种密钥库,其中访问由主密码控制。

编辑:回答以下OP的后续问题:

即使如此,主密码也必须存储在系统上,否则用户必须为每个请求手动输入它(我认为如果您不信任 root,即使将其存储在内存中也是不安全的)。

这都是相对的。如果你真的很偏执,你不会将密钥存储在任何你不能完全控制的机器上。另一方面,大多数人准备相信 root 没有受到损害,并且(作为后备)拥有 root 访问权限的人需要付出一些努力才能破解密钥库。内存中密钥库的未锁定副本可能被视为“足够安全”。当然,许多用户密钥库软件似乎都基于这种假设。

为什么目录要设置为0700?即使是0777,里面的0600的文件别人还是无法读取的吧?

部分是一般性偏执,部分是腰带和大括号,部分是向其他用户发出“不要干涉我的私人物品”的信号,部分是通过替换您的密钥文件来防止他人入侵。最后一点可能很关键……也可能不是……具体取决于您的应用程序如何使用密钥。

Storing a key in ~/.yourApp will work, provided that you set the permissions of the key file to 0600 and the permissions of the ~/.yourApp directory to 0700.

Of course you are relying on people not being able / willing to use root access to access other users' key files. If that is a concern you are going to need to use some kind of keystore where access is controlled by a master passphrase.

EDIT : in answer to the OP's followup questions below:

Even then the master passphrase must be stored on the system, or users will have to enter it manually for every request (I assume even storing it in memory is unsafe if you don't trust root).

It is all relative. If you are really paranoid, you don't store the key on any machine that you don't totally control. On the other hand, most people are prepared to trust that root has not been compromised and (as a fallback) that it requires some effort for someone with root access to break a keystore. An unlocked copy of your keystore in memory may count as "safe enough". Certainly, a lot of user keystore software seems to work on that assumption.

Why should the directory be set to 0700? Even if it was 0777, a file inside it with 0600 would still be unreadable to others, right?

Partly general paranoia, partly belt-and-braces, partly a sign to other users to "keep your nose out of my private stuff", and partly to protect against someone by replacing your key file. The last point could be critical ... or not ... depending on exactly how the key is used by your application.

不回头走下去 2024-08-29 00:44:47

主目录中有隐藏文件夹,简单命名为.appname。用户可以阅读它们。

如何生成随机密钥并将其存储在 ~/.yourappname 中?

There are hidden folders in the home directory, simply named .appname. They can be read by the user.

How just generating a random key, and store it in ~/.yourappname?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文