我的项目需要我为某些用户禁用 sftp,但这些用户仍然需要通过 ssh 连接。有谁知道如何实现这一点?
我在 看到了更改文件的建议/etc/ssh/sshd_config,但我不确定要更改什么。
一般来说,由于其他人列出的原因,这样做是不好的安全做法。但是,我认为您的任务的重点是教您可以根据各种标准设置条件配置部分。
这样做的方法是使用Match条件块*。
Match User bob
Subsystem sftp /bin/false
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅部分sshd_config(5)下方Match,并在 上进行匹配Group。
*有不止一种方法可以做到。
小智 6
这没有任何意义,它是通过无用的默默无闻的安全性。任何可以使用 SSH 的用户都可以传输他们能够通过 SSH 会话读取的任何文件。如果您有权限,您也可以进行写作。
例如,您可以使用以下方法通过 ssh 下载 /etc/passwd(不需要 scp/sftp 会话):ssh foo@bar.com "cat /etc/passwd" > passwdcopy
如果您可以通过 SSH 在屏幕上看到它,那么您可以轻松地将其复制为文件。
唯一有意义的方法是,如果您有一个强制执行安全策略的自定义受限 shell。
但是,与此相反的情况确实有意义(禁用 ssh shell 但启用 leaving scp/sftp),因为您无法通过 sftp/scp 执行任意命令,而您可以通过 ssh shell 执行。
PS:我假设您授予的 SSH shell 是一个允许任意执行的标准 shell。如果不是这种情况,那么请参阅:如何为特定用户或组禁用 sftp 子系统?并查看 sshd_config 的子系统配置选项。
小智 5
Match Group nosft
Subsystem sftp /bin/false
Run Code Online (Sandbox Code Playgroud)
我更喜欢为此使用一个组。
它对于具有受限 shell 的用户非常有用。有时我会向客户端提供 ssh 访问权限,以便他们可以通过将 shell 设置为转储数据的脚本来访问数据库的 sql 转储。切断他们与 scp 的联系似乎也是一个明智的主意。他们无权运行cat通过 ssh 传输文件。
可以全局启用 SFTP,并仅对部分用户禁用 SFTP。
\n\n如果您希望用户获得常规的 shell 提示符,则此方法不起作用。\n这也没有意义,因为如果你有 shell 访问权限,你就可以绕过大多数东西。\n只有当你只想授予对特定程序的访问权限时,它才会起作用。
\n\n我个人需要这个,因为我想通过 SSH 来访问一些 git 存储库,并且我喜欢禁用不需要的系统。在这种情况下,不需要 SFTP。
\n\n要匹配一组用户,您可以使用Match关键字配置 SSH。来自\nsshd_config(5)手册:
Match\n ...\n\n The arguments to Match are one or more criteria-pattern pairs or the\n single token All which matches all criteria. The available criteria\n are User, Group, Host, LocalAddress, LocalPort, and Address. The\n match patterns may consist of single entries or comma-separated\n lists and may use the wildcard and negation operators described in\n the PATTERNS section of ssh_config(5).\n\n ...\nRun Code Online (Sandbox Code Playgroud)\n\n举几个例子:
\n\nMatch User eva匹配“eva”用户Match User stephen,maria匹配“stephen”和“maria”用户Match Group wheel,adams,simpsons匹配“wheel”、“adams”、“simpsons”\n组如果您想了解更多信息,手册中有很多内容sshd_config(5)。
通常,当您通过 SSH 连接时,您会获得用户的登录 shell,但可以将 SSH 配置为强制执行特定命令。该命令对于任何 SSH 连接(包括 SFTP)都是强制执行的,因此您可以选择强制执行您想要的命令。
\n\n强制命令可以用ForceCommand关键字来配置。来自\nsshd_config(5)手册:
ForceCommand\n Forces the execution of the command specified by ForceCommand,\n ignoring any command supplied by the client and ~/.ssh/rc if\n present. The command is invoked by using the user\'s login shell\n with the -c option. This applies to shell, command, or subsystem\n execution. It is most useful inside a Match block. The command\n originally supplied by the client is available in the\n SSH_ORIGINAL_COMMAND environment variable. Specifying a command of\n \xe2\x80\x9cinternal-sftp\xe2\x80\x9d will force the use of an in-process sftp server that\n requires no support files when used with ChrootDirectory. The\n default is \xe2\x80\x9cnone\xe2\x80\x9d.\nRun Code Online (Sandbox Code Playgroud)\n\n因此您可以使用 强制执行您想要的受约束命令ForceCommand <your command>。\n例如:
Match User kim\n ForceCommand echo \'successful login man, congrats\'\nRun Code Online (Sandbox Code Playgroud)\n\n在我想要授予 git 访问权限的情况下,我只需要用户有权访问git-shell. 这是为我的 git 用户禁用 SFTP 的部分,以及\n一些安全选项:
Match Group git\n\n # have to do this instead of setting the login shell to `git-shell`,\n # to disable SFTP\n ForceCommand /usr/bin/git-shell -c "$SSH_ORIGINAL_COMMAND"\n\n # disable stuff we don\'t need\n AllowAgentForwarding no\n AllowTcpForwarding no\n AllowStreamLocalForwarding no\n PermitOpen none\n PermitTunnel no\n PermitTTY no\n X11Forwarding no\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
30069 次 |
| 最近记录: |