什么是/ bin / rbash?


14

我正在学习Common Shell程序

当我运行时cat /etc/shells,它显示:

# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash

这是/bin/rbash什么 它用于脚本编制吗?


6
哪一部分man rbash不清楚?
Stig Hemmer

1
@StigHemmer。我没做 man rbash还给了我详细信息。谢谢。
雏菊

3
阅读手册页始终应该是您第一次了解工具的尝试。您还应该在显示它的机器上阅读它,以确保阅读正确的版本。

Answers:


16

来自维基百科

受限外壳是Unix外壳,它限制了其中运行的交互式用户会话或外壳脚本可用的某些功能。它旨在提供附加的安全层,但不足以允许执行完全不受信任的软件。在原始的Bourne shell [1]及其后来的bash [2]和Korn shell中发现了受限模式操作。[3] 在某些情况下,受限制的外壳程序与chroot监狱一起使用,以进一步尝试限制对整个系统的访问。

有关适用于受限外壳的限制,请参见Soren A的答案

您可以bash在受限模式下运行

bash -r
bash --restricted

在我的系统上:

$ file /bin/rbash
/bin/rbash: symbolic link to bash

所以如果我跑步/bin/rbash,我就会跑步bash

创建一个名为rbash的链接即可直接指向bash。尽管这直接调用了bash,但没有使用-ror --restricted 选项,但是bash确实认识到它是通过rbash调用的,并且确实是受限制的shell。

正如您可以轻松测试的那样:

zanna@monster:~$ rbash
zanna@monster:~$ cd playground
rbash: cd: restricted

1
似乎有很多限制。那有什么用呢?它在脚本中使用吗?
雏菊

3
可以将其设置为要捕获到特定目录中的用户的默认外壳程序,例如@passa
Zanna

2
@passa不是脚本,而受限制的外壳对于脚本来说毫无用处。由于您知道或可以确定脚本中执行了哪些操作,因此没有必要使用受限制的Shell进行脚本编写。
muru

@muru好的。因此,这可以用于zanna在评论中说的目的。
雏菊

1
这对系统管理员很有帮助,因为它可以防止其他用户执行危险的任务。它对最终用户没有太大用处。

17

rbash是bash的受限版本(降低了功能)。看到这篇文章:https : //en.wikipedia.org/wiki/Restricted_shell

从文章:

受限外壳程序中不允许执行以下操作:

changing directory
specifying absolute pathnames or names containing a slash
setting the PATH or SHELL variable
redirection of output

bash增加了更多限制,包括:

limitations on function definitions
limitations on the use of slash-ed filenames in bash builtins

受限的Korn外壳中的限制与受限的Bourne外壳中的限制非常相似。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.