創建SFTP用戶並指定訪問目錄 Linux


1、創建登錄用戶及用戶組   --可以根據自身磁盤掛載情況制定用戶home目錄 -d 選項

groupadd test1
mkdir -p /data/test1 useradd test1 -g test1 -d /data/test1
echo "123" |passwd --stdin test1 &>/dev/null

2、vim /etc/ssh/sshd_config

Subsystem      sftp    /usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
Match User test1
        X11Forwarding no
        AllowTcpForwarding no
        PermitTTY no
#       ForceCommand cvs server
        ForceCommand internal-sftp
        ChrootDirectory /home/test1

Match Group  匹配sftp組的用戶,如果要匹配多個組,多個組之間用逗號分割

Match User  匹配用戶

X11Forwarding no  設置不允許SSH的X轉發

3、連接測試

 

可以看到連接失敗  ,這樣需要我們把用戶home目錄改為root權限

 

 

可以看到登錄成功  但是沒有寫權限,無法進行文件上傳,可以在用戶home目錄下創建一個文件夾 比如:我這里在test1目錄下創建了一個 upload目錄, 將目錄權限屬組屬主給test1 即可解決此問題

PS#####  過程中還有一個踩坑的地方 就是普通用戶home目錄創建在home目錄下的時候遠程連接時會出現  ----無法遠程目錄  后來將用戶home目錄指定在/data下解決了  相對得sshd_config中 ChrootDirectory 也要修改為/data/test1 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM