Centos 7 設定 SFTP

來源:互聯網
上載者:User

近期要給伺服器設定一個SFTP使用者,可以上傳刪除修改的SFTP,但是禁止該使用者SSH登入。這裡記錄下來 先升級

yum update

fox.風 建立使用者組 sftp

使用者組名為sftp

groupadd sftp
建立使用者 test

例如這個使用者名稱為 test

useradd -G sftp -s /sbin/nologin test 

-s 禁止使用者ssh登陸
-G 加入sftp 使用者組 建立密碼

passwd test 
修改設定檔sshd_config
vim /etc/ssh/sshd_config

修改為如下

....##下面這行注釋掉#Subsystem sftp /usr/libexec/openssh/sftp-server##後面加入Subsystem sftp internal-sftp#注意,以下要 放在 本檔案的最後行,否則 root使用者無法登陸Match Group sftpX11Forwarding noAllowTcpForwarding noChrootDirectory %h                      ForceCommand internal-sftp

說明
Match Group sftp 匹配sftp使用者組中的使用者
ChrootDirectory %h 只能訪問預設的使用者目錄(自己的目錄),例如 /home/test 設定目錄許可權

chown root:sftp /home/testchgrp -R sftp /home/testchmod -R 755 /home/test#設定使用者可以上傳的目錄,改目錄下允許使用者上傳刪除修改檔案及檔案夾mkdir /home/test/uploadchown -R test:sftp /home/test/uploadchmod -R 755 /home/test/upload
重啟ssh
systemctl restart sshd.service
連結

建立一個 終端連結,或者在 FTP 用戶端中使用SFTP 模式連結(輸入相關的IP使用者名稱及連接埠)

sftp test@192.1.1.1
F&Q

如果報類似以下錯誤

sftp Connection to  closed by remote host.或者Write failed: Broken pipe Couldn't read packet: Connection reset by peer 

這個就是該使用者根目錄的許可權問題,chown root:sftp /home/test 設定為root使用者即可解決,目錄許可權為755

其他,檢測 /etc/selinux/config中SELINUX 是否為SELINUX=disabled,如果不是請改正

參考:http://blog.csdn.net/dodott/article/details/50945888
https://linux.cn/article-3692-1.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.