限制用户只能访问一个特定文件,不能访问其他任何文件
Restrict user access to JUST ONE specific file and nothing else
我有一种情况,我希望用户能够 rwx 访问一个特定的文件,命令 nano
、/bin/bash
和 NOTHING ELSE。用户将能够使用 ssh 登录。
我遵循了 Victor Wong 对这个问题的第二个回答:How to limit user commands in Linux 用 nano 设置了这个东西,但到目前为止我无法限制对这个文件的访问。
使用正常的 linux 权限,用户将始终能够导航到 /etc 甚至阅读 /etc/groups 等等。
我尝试了这两个命令:
setfacl -m u:myuser:0 /
然后 setfacl -m u:myuser:rwx /etc/network/interfaces
但是 linux 告诉我 /etc/network/interfaces
的权限被拒绝,我猜是因为对 / 的限制被优先考虑或者只是排在第一位。
自从我读到你仍然可以用 nano 打开其他文件后,我就没有尝试过 root jail。我说得对吗?
我 googled 几个小时了,玩了几个小时,但还没有找到解决方案。你们能帮帮我吗,或者至少也给我流行语 google 试试看?
哪个用户尝试了 运行
setfacl -m u:myuser:0 /
setfacl -m u:myuser:rwx /etc/network/interfaces
命令?
/etc/network/interfaces 是否属于该用户?
您可以分享当前的 getfacl
命令输出吗?
请尝试更具体地说明用户和操作。
顺便说一下,对于文件,您可以尝试将 -M
选项与 setfacl 一起使用,并使用像 /etc/network/nterfaces
.
的所有者这样的特权用户来执行此操作吗?
setfacl - u:myuser:rwx /etc/network/interfaces
你可以试试这个。
我最终按照本文中的步骤创建了一个 chroot 监狱:
https://www.tecmint.com/restrict-ssh-user-to-directory-using-chrooted-jail/
通过为我需要用户能够编辑的文件创建硬 link。我还在可用命令中添加了 nano
。
它就像一个魅力。
我还跳过了将 ForceCommand internal-sftp
添加到 sshd_config
文件的子步骤 14,因为我仍然需要 ssh。
以防有人遇到这个 post 并想添加 nano
:
您需要将 /lib/terminfo
及其所有内容添加到您的 /home/myuser/lib/
文件夹中!
我会写一个 setuid C program using relevant syscalls(2), compile it carefully (into a static executable), have that C code being reviewed by colleagues, and make that executable the login shell (see chmod(1), execve(2), seteuid(2), credentials(7), shells(5), elf(5) and passwd(5) and pam_shells(8)...) 那个特定用户。
编写 setuid 可执行文件时要小心 (错误会打开一个巨大的安全漏洞)。阅读Advanced Linux Programming
顺便说一句,一旦你的用户是 运行 /bin/bash
,他就可以做任何事情。也许您只想允许 restricted bash shell?
我有一种情况,我希望用户能够 rwx 访问一个特定的文件,命令 nano
、/bin/bash
和 NOTHING ELSE。用户将能够使用 ssh 登录。
我遵循了 Victor Wong 对这个问题的第二个回答:How to limit user commands in Linux 用 nano 设置了这个东西,但到目前为止我无法限制对这个文件的访问。
使用正常的 linux 权限,用户将始终能够导航到 /etc 甚至阅读 /etc/groups 等等。
我尝试了这两个命令:
setfacl -m u:myuser:0 /
然后 setfacl -m u:myuser:rwx /etc/network/interfaces
但是 linux 告诉我 /etc/network/interfaces
的权限被拒绝,我猜是因为对 / 的限制被优先考虑或者只是排在第一位。
自从我读到你仍然可以用 nano 打开其他文件后,我就没有尝试过 root jail。我说得对吗?
我 googled 几个小时了,玩了几个小时,但还没有找到解决方案。你们能帮帮我吗,或者至少也给我流行语 google 试试看?
哪个用户尝试了 运行
setfacl -m u:myuser:0 /
setfacl -m u:myuser:rwx /etc/network/interfaces
命令?
/etc/network/interfaces 是否属于该用户?
您可以分享当前的 getfacl
命令输出吗?
请尝试更具体地说明用户和操作。
顺便说一下,对于文件,您可以尝试将 -M
选项与 setfacl 一起使用,并使用像 /etc/network/nterfaces
.
setfacl - u:myuser:rwx /etc/network/interfaces
你可以试试这个。
我最终按照本文中的步骤创建了一个 chroot 监狱:
https://www.tecmint.com/restrict-ssh-user-to-directory-using-chrooted-jail/
通过为我需要用户能够编辑的文件创建硬 link。我还在可用命令中添加了 nano
。
它就像一个魅力。
我还跳过了将 ForceCommand internal-sftp
添加到 sshd_config
文件的子步骤 14,因为我仍然需要 ssh。
以防有人遇到这个 post 并想添加 nano
:
您需要将 /lib/terminfo
及其所有内容添加到您的 /home/myuser/lib/
文件夹中!
我会写一个 setuid C program using relevant syscalls(2), compile it carefully (into a static executable), have that C code being reviewed by colleagues, and make that executable the login shell (see chmod(1), execve(2), seteuid(2), credentials(7), shells(5), elf(5) and passwd(5) and pam_shells(8)...) 那个特定用户。
编写 setuid 可执行文件时要小心 (错误会打开一个巨大的安全漏洞)。阅读Advanced Linux Programming
顺便说一句,一旦你的用户是 运行 /bin/bash
,他就可以做任何事情。也许您只想允许 restricted bash shell?