美文网首页
2023.05.10 在Linux中创建一个用户并限制其访问特定

2023.05.10 在Linux中创建一个用户并限制其访问特定

作者: 薛定谔的猴子 | 来源:发表于2023-05-09 11:50 被阅读0次

要创建一个用户并限制其访问特定目录,您需要执行以下步骤:

用户假设是res_user
目录假设是usr/local/code/resource

  1. 创建新的用户账户:

    • 在终端中以root身份登录。
    • 运行以下命令来创建新用户:sudo adduser username
    • username替换为您要创建的用户名,当前假设是res_user
    • 运行passwd res_user,并按照提示输入密码和其他相关信息
  2. 创建用户组:

    • 使用groupadd restricted命令创建用户组
    • 并将res_user放到用户组中usermod -g restricted res_user
  3. 更改目录的权限和所有权:

    • chown res_user:restricted /usr/local/code/resource
    • chmod g+rx /usr/local/code/resource
  4. 用户限制使用shell模式:

    • usermod -s /bin/rbash res_user
  5. 设置/etc/ssh/sshd_config 配置文件,在最后加上

    Match Group restricted
        ForceCommand internal-sftp
        ChrootDirectory /usr/local/code
        PermitTunnel no
        AllowAgentForwarding no
        AllowTcpForwarding no
        X11Forwarding no
  1. 重启sshd
    systemctl restart sshd

相关文章

网友评论

      本文标题:2023.05.10 在Linux中创建一个用户并限制其访问特定

      本文链接:https://www.haomeiwen.com/subject/lkursdtx.html