Lan*_*nes 54 linux ssh account-restrictions
如何限制 SSH 服务器上的用户只允许他们使用SSH TUNNELING的权限?即,即使他们通过 SSH 登录,他们也无法运行命令。
我的 Linux 服务器是 Ubuntu 11.04 和 OpenWrt。
Cal*_*leb 53
在服务器端,您可以通过将其用户 shell 设置为/bin/true
. 这将允许他们进行身份验证,但实际上不会运行任何东西,因为他们没有一个 shell 来运行它。这意味着他们将被限制在 SSH 能够提供给他们的任何东西的子集上。如果它提供端口转发,他们仍然能够做到这一点。
在客户端,您可能希望与-N
. 这会阻止客户端请求远程命令(例如 shell),它会在身份验证部分完成后停止。感谢评论者指出这一点。
aef*_*aef 39
以下的优点是也不允许 X11 和 SSH 代理套接字转发,这可能仍然以 Calebs 方式允许。另一个优点是,如果用户能够通过任何其他方式更改他的默认 shell,这仍然会将他的 SSH 访问限制为仅 TCP 转发。
将以下内容放入您的/etc/ssh/sshd_config
:
Match User that-restricted-guy
AllowTcpForwarding yes
X11Forwarding no
AllowAgentForwarding no
ForceCommand /bin/false
Run Code Online (Sandbox Code Playgroud)
允许用户that-restricted-guy
通过支持 SSH 的机器转发任何 TCP 连接(连接到这台机器,localhost
甚至从这台机器到其他机器的连接)。
如果您希望它更具限制性(这是一个好主意),您还可以执行以下操作:
Match User even-more-restricted-guy
PermitOpen 127.0.0.1:12345
X11Forwarding no
AllowAgentForwarding no
ForceCommand /bin/false
Run Code Online (Sandbox Code Playgroud)
这将允许用户even-more-restricted-guy
只将连接转发到 127.0.0.1 TCP 端口 12345(因为它可以通过启用 SSH 的机器看到)。
当用户正常连接时,他现在将立即断开连接,因为/bin/false
将触发该命令,该命令只会立即退出,代码为 1。如果您想避免这种情况并保持转发连接打开,请将-N
标志添加到ssh
命令中。这不会尝试执行任何命令,但仍允许设置 TCP 转发。
应该在后一种设置中工作的转发命令的示例:
ssh -L 12345:127.0.0.1:12345 -N even-more-restricted-guy@insert-your-machine
Run Code Online (Sandbox Code Playgroud)
小智 6
假设您的 ssh 版本足够新以支持它(openssh 5.x+),您可以通过匹配组来控制人们可以在 ssh 中执行的操作。
基本上,我们将他们视为 sftp 用户,但允许 tcp 转发并可选择指定他们可能转发到的目的地。如果你给他们一个主目录,但没有在它下创建任何目录,他们就不能传输任何文件,因为他们没有这样做的权限。
Match Group nicepeople
PubkeyAuthentication yes
PasswordAuthentication yes
PermitEmptyPasswords no
GatewayPorts no
ChrootDirectory /opt/dummy_location/%u
ForceCommand internal-sftp
AllowTcpForwarding yes
PermitOpen 192.168.0.8:22
PermitOpen 192.168.0.5:8080
# Or leave out the PermitOpen to allow forwarding to anywhere.
HostbasedAuthentication no
RhostsRSAAuthentication no
AllowAgentForwarding no
Banner none
Run Code Online (Sandbox Code Playgroud)
您可以为希望提供不同行为或限制的每个组重复这些匹配组块。
您可以使用 iptables 进一步控制此人可以访问网络的位置
/sbin/iptables -I OUTPUT -m owner --gid-owner 500 -j REJECT
/sbin/iptables -I OUTPUT -m owner --gid-owner 500 -m tcp -p tcp -d 192.168.0.0/24 -j ACCEPT
Run Code Online (Sandbox Code Playgroud)
这假设“nicepeople”组的 GID 为 500。
上面的一些 ssh 选项在旧版本的 openssh 中可用,但不在匹配组部分中。匹配组在 OpenSSH 4.x 及更早版本中非常有限。
归档时间: |
|
查看次数: |
39827 次 |
最近记录: |