[不懂/寻问/伸手]linux系统有法子让某个文件只让特定程序读取嘛?(初步方案形成)

其它类软件,非上述版软件
回复
ghome9
帖子: 38
注册时间: 2023-01-11 11:12
系统: ubuntu22.04

[不懂/寻问/伸手]linux系统有法子让某个文件只让特定程序读取嘛?(初步方案形成)

#1

帖子 ghome9 » 2024-03-14 20:32

使用Keepassxc中。 数据库密码设置长40位,使用过程中如果锁定 再解锁非常痛苦。
当然Keepassxc 也提供了 通过key file 解锁的选项。但是如果key file 不封锁起来 任何人可读的话,又非常不安全。
所以来请教下,linux系统方法 有能设定文件只让特定程序读取嘛, 其他普通用户看不了 权限为0。
目前在用 ubuntu 22.04
目标是 解锁要双重验证 短密码 加key file,锁定后,解锁只需要短数密码/类PIN码。 key file的安全需要确保。
(程序自动创建的keyfile是400权限,任何人可复制;所以想说搞个文件夹只让程序通过,用来保护限制)
程序提升到sudo权限的话,可能过于危险;所以才来问问有没有限定文件权限的方法(只让特定程序access)

03-17 更新:
1.简单方案
选择不记住keyfile文件路径,每次解锁手动选择文件;keefile不使用程序生成的keefile,自选一个文件来使用。
toools->setting->general->basic setting 的remember database key file 是用来选择是否记住keyfile路径的。
database->database security->security->database credentials 里add key file 自选一个文件(文件选择于N多文件中的某一个,增加迷惑性)。
重点key file 记得修改成只读属性 另外多重备份啊,不然丢了就完了。
(toools->setting->general->basic setting 下拉到最下面 有language,可更改为中文显示)
2.进一步方案
使用其他用户运行程序,这样可以设定个文件夹保证其他普通用户访问不了。
用户如下 ptuser suuser keyuser
sudo useradd -r -m -d /home/keyuser -s /bin/bash 选择-r是为了在登录界面隐藏该账号(登录界面账号太多也烦)
用keyuser 创建个目录并于它下面创建个文件 (是否增加简单方案,自行考量) 然后chmod 把目录与文件修改成500,单用户访问

使用过程:

终端输入 xhost +SI:localuser:keyuser (使keyuser可以于当前账户的X11界面启动程序)
切换keyuser
keepassxc 启动程序 (现存的keepass数据库的目录与文件权限,记得修改成keyuser可写可执行,也可以复制到keyuser专属目录进一步保护数据库文件-但相应的数据库文件的通用性就没有了。)
这样就能于 公用账户使用自己的keepassxc了, 还能是短密码还有一定的安全性

xhost永久性增加 keyuser 某一方案如下:
ptuser 终端下
nano ~/.bashrc
在最后面添加命令
xhost +si:localuser:keyuser 会在每次启动都提示 (si SI 都有效果,有没有其它隐患区别就不知道了。)
xhost +si:localuser:keyuser > /dev/null 不输出提示信息 (两种方案,自行选择是否要输出提示)
保存退出 重载配置
source ~/.bashrc 从此以后不用每次都输入命令了,但是安全性要自己考量。

ps:谢谢楼下各位大佬的指点。
上次由 ghome9 在 2024-03-17 11:28,总共编辑 1 次。
头像
astolia
论坛版主
帖子: 6450
注册时间: 2008-09-18 13:11

Re: [不懂/寻问/伸手]linux系统有法子让某个文件只让特定程序读取嘛?

#2

帖子 astolia » 2024-03-14 21:54

你可以选择藏木于林,选择一个特定的图片/视频/电子书之类的作为keyfile,和其他的同类文件放一起

非要按你那样的想法,要想简单点就是给文件设置成只有特定的用户/组可以访问,然后用sudo以那个用户/组来执行Keepassxc
或者上selinux

会写shell脚本的话,选择会更多一些
头像
懒蜗牛Gentoo
论坛版主
帖子: 7353
注册时间: 2007-03-02 17:36
系统: Linux Mint

Re: [不懂/寻问/伸手]linux系统有法子让某个文件只让特定程序读取嘛?

#3

帖子 懒蜗牛Gentoo » 2024-03-15 8:42

可以了解一下文件的s权限。我以前用过,记不太清了。大概意思就是有s权限的文件在别的用户执行的时候会临时获得该文件所有者的权限。这样你把你的Keepassxc可执行文件所有者设置成比如keepuser,并具有s权限。然后把你的key file设置为只有keepuser可读,应该就可以了。
虽然世上没有完美的东西,但这并不影响我们追求完美,因为只有偏执狂才TMD能成功。
10.04新手入门——笨兔兔讲述自己的故事
头像
astolia
论坛版主
帖子: 6450
注册时间: 2008-09-18 13:11

Re: [不懂/寻问/伸手]linux系统有法子让某个文件只让特定程序读取嘛?

#4

帖子 astolia » 2024-03-15 9:51

懒蜗牛Gentoo 写了: 2024-03-15 8:42 可以了解一下文件的s权限。我以前用过,记不太清了。大概意思就是有s权限的文件在别的用户执行的时候会临时获得该文件所有者的权限。这样你把你的Keepassxc可执行文件所有者设置成比如keepuser,并具有s权限。然后把你的key file设置为只有keepuser可读,应该就可以了。
这个对于gtk程序是不行的,用了gtk库的程序会直接拒绝执行。keepassxc虽然是qt写的,但如果设置成了用gtk风格外观,一样会调用gtk库
ghome9
帖子: 38
注册时间: 2023-01-11 11:12
系统: ubuntu22.04

Re: [不懂/寻问/伸手]linux系统有法子让某个文件只让特定程序读取嘛?

#5

帖子 ghome9 » 2024-03-15 16:23

懒蜗牛Gentoo 写了: 2024-03-15 8:42 可以了解一下文件的s权限。我以前用过,记不太清了。大概意思就是有s权限的文件在别的用户执行的时候会临时获得该文件所有者的权限。这样你把你的Keepassxc可执行文件所有者设置成比如keepuser,并具有s权限。然后把你的key file设置为只有keepuser可读,应该就可以了。
sudo cp /home/ubun/Downloads/tmp_fold/keetest ./
sudo chown keeuser:keeuser keetest
sudo chown keeuser:keeuser /usr/bin/keepassxc
sudo chmod 4755 /usr/bin/keepassxc
-rwsr-xr-x 1 keeuser keeuser 3738104 9月 14 2021 /usr/bin/keepassxc*
keepassxc
FATAL: The application binary appears to be running setuid, this is a security hole.
Aborted (core dumped)
上面是初步试验的结果,不行。 我是用APT安装的keepassxc.
是不是不能只换一个主程序,它后面那一大堆信赖都要改的。
如果用户是root 设了s位, 那会不会很不安全 它可以访问一大堆地方;隐性安全性漏洞?
ghome9
帖子: 38
注册时间: 2023-01-11 11:12
系统: ubuntu22.04

Re: [不懂/寻问/伸手]linux系统有法子让某个文件只让特定程序读取嘛?

#6

帖子 ghome9 » 2024-03-15 16:40

astolia 写了: 2024-03-14 21:54 你可以选择藏木于林,选择一个特定的图片/视频/电子书之类的作为keyfile,和其他的同类文件放一起
keepass_show.png
启动界面是这样子,隐藏不了(如果是公用账户,隐藏不了)。
astolia 写了: 2024-03-14 21:54 非要按你那样的想法,要想简单点就是给文件设置成只有特定的用户/组可以访问,然后用sudo以那个用户/组来执行Keepassxc
报错如下(GUI界面,是否换成命令行程序才会有可行性?):
su - keeuser
Password:
keeuser@uubun-H81MLV3:~$ keepassxc
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

Aborted (core dumped)
su - root
sudo keepassxc
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

Aborted

至于selinux 我小小学习一下看看,看看会不会测试运行。
实在不行 就痛苦点也能用就是了。
头像
astolia
论坛版主
帖子: 6450
注册时间: 2008-09-18 13:11

Re: [不懂/寻问/伸手]linux系统有法子让某个文件只让特定程序读取嘛?

#7

帖子 astolia » 2024-03-15 17:25

ghome9 写了: 2024-03-15 16:40
astolia 写了: 2024-03-14 21:54 你可以选择藏木于林,选择一个特定的图片/视频/电子书之类的作为keyfile,和其他的同类文件放一起
keepass_show.png
启动界面是这样子,隐藏不了(如果是公用账户,隐藏不了)。
???
我说的是,只要你在keepassxc的设置里让它不要记住上次用的keyfile,你自己又不大嘴巴到处嚷嚷,那么谁会知道硬盘上的哪个文件是keyfile?你应该不会傻到把keyfile的文件名设成是“keepassxc的keyfile”吧?

ghome9 写了: 2024-03-15 16:40 报错如下(GUI界面,是否换成命令行程序才会有可行性?):
su - keeuser
Password:
keeuser@uubun-H81MLV3:~$ keepassxc
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

Aborted (core dumped)
su - root
sudo keepassxc
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

Aborted
这个报错是x11的安全机制,默认不允许其他用户干涉当前x11环境,用xhost授权一下就行

代码: 全选

xhost +SI:localuser:keeuser
图省事也可以

代码: 全选

xhost +local:
还有,你是不是以为sudo不能指定用户/组才去用su?
回复