2023.05.10 在Linux中創(chuàng)建一個(gè)用戶并限制其訪問特定目錄

要?jiǎng)?chuàng)建一個(gè)用戶并限制其訪問特定目錄,您需要執(zhí)行以下步驟:

用戶假設(shè)是res_user
目錄假設(shè)是usr/local/code/resource

  1. 創(chuàng)建新的用戶賬戶:

    • 在終端中以root身份登錄。
    • 運(yùn)行以下命令來創(chuàng)建新用戶:sudo adduser username
    • username替換為您要?jiǎng)?chuàng)建的用戶名,當(dāng)前假設(shè)是res_user。
    • 運(yùn)行passwd res_user,并按照提示輸入密碼和其他相關(guān)信息
  2. 創(chuàng)建用戶組:

    • 使用groupadd restricted命令創(chuàng)建用戶組
    • 并將res_user放到用戶組中usermod -g restricted res_user
  3. 更改目錄的權(quán)限和所有權(quán):

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

    • usermod -s /bin/rbash res_user
  5. 設(shè)置/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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容