無法 chroot 使用者

無法 chroot 使用者

我的 ssh 伺服器已經正常工作了 4 年,所以我只想添加一個用戶 + chroot 他到特定資料夾。

> useradd -m -c /home/thomas -s /bin/sh thomas
> passwd thomas
> chmod 755 /home/thomas
> chown root: /home/thomas
> service ssh restart

當我這樣做時,我連接通過ssh並且我的sftp連接有效。問題是我想 chroot 到特定資料夾。

> vim /etc/ssh/sshd_config

在文件末尾添加:

Match user thomas
    ChrootDirectory /home/%u

當我只添加這個時,這不應該改變什麼,對吧?設定應該是相同的,我仍然應該能夠連接或使用 sftp...所以我重新啟動,service ssh restart並且無法再與 sftp 連接。

萬一:

root@xx:/etc/nginx/sites-enabled# /usr/sbin/sshd -v
sshd: illegal option -- v
OpenSSH_6.0p1 Debian-4+deb7u6, OpenSSL 1.0.1t  3 May 2016
usage: sshd [-46DdeiqTt] [-b bits] [-C connection_spec] [-c host_cert_file]
            [-f config_file] [-g login_grace_time] [-h host_key_file]
            [-k key_gen_time] [-o option] [-p port] [-u len]
root@xx:/etc/nginx/sites-enabled#

我究竟做錯了什麼?

答案1

手冊sshd_config指出

必須ChrootDirectory包含支援使用者會話所需的檔案和目錄。對於互動式會話,這至少需要一個 shell(通常為sh(1))和基本/dev節點(例如null(4)zero(4)stdin(4)stdout(4)stderr(4)tty(4)設備)。對於使用 SFTP 的檔案傳輸會話,如果使用進程內 sftp 伺服器,則不需要額外的環境配置,但使用記錄的會話可能需要/dev/log在某些作業系統上的 chroot 目錄中(請參閱sftp-server(8)參考資料)。

您應該建立該dev目錄,然後將/dev/MAKEDEV腳本複製到那裡。使用腳本建立所需的設備檔案。

對於互動式用戶,您還需要在 chroot 中安裝必要的二進位檔案和關聯的程式庫。

對「進程內 sftp 伺服器」的引用意味著ForceCommand internal-sftp應該在您的區塊中使用Match

注意:摘錄自 OpenSSH 7.5,因為我無權存取任何較舊的 SSH 實作。

相關內容