chroot 및 non-chroot sftp를 설정하는 방법은 무엇입니까?

chroot 및 non-chroot sftp를 설정하는 방법은 무엇입니까?

chroot sftp 사용자와 chroot가 아닌 sftp 및 ssh 사용자만 허용하도록 Openssh 서버를 설정하려고 합니다. 내 /etc/ssh/sshd_config(주석 및 빈 줄 제거됨)의 간단한 버전은 다음과 같습니다.

Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 768
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp intenal-sftp
UsePAM yes
Match Group sftpusers
        ChrootDirectory /var/sftp/%u
        ForceCommand internal-sftp

내가 이 일을 통해 얻은 것:

  • sftupsers 그룹의 사용자는 파일을 디렉터리에 SFTP할 수 있지만 로그인할 수는 없습니다. 확인하시기 바랍니다.
  • sftpusers에 속하지 않은 사용자는 SSH를 통해 로그인할 수 있습니다. 확인하다.
  • sfttpusers에 없는 사용자는 다음을 수행할 수 있습니다.아니요sftp 파일. 이런.

Subsystem sftp-line을 주석 처리된 버전으로 변경 하면 "권한이 있는" 사용자는 sftp 및 ssh를 사용할 수 있지만 chroot된 사용자는 더 이상 sftp를 사용할 수 없습니다.

위의 구성 파일을 사용하면 Connection closed by server with exitcode 127FileZilla 및 psftp에서 Fatal: Received unexpected end-of-file from SFTP server오류 메시지가 나타납니다 .

이 문제를 해결하는 방법을 아시나요?

답변1

Subsystem sftp intenal-sftp

"내부"여야 합니다.아르 자형나르”.

답변2

항상 배치할 필요는 없습니다 Subsystem sftp internal-sftp. 이것은 큰 오해입니다.

무엇을 정의합니까 Subsystem? 점검 해보자 sshd_config(5):

 Subsystem
         Configures an external subsystem (e.g. file transfer daemon).
         Arguments should be a subsystem name and a command (with optional
         arguments) to execute upon subsystem request.

         The command sftp-server implements the SFTP file transfer
         subsystem.

         Alternately the name internal-sftp implements an in-process SFTP
         server.  This may simplify configurations using ChrootDirectory
         to force a different filesystem root on clients.

         By default no subsystems are defined.

chroot의 모든 파일을 설정하지 않으려는 경우 에만 sftp하위 시스템을 변경 하면 됩니다(예:internal-sftpChrootDirectory

Subsystem sftp internal-sftp예를 들어, 특별한 작업을 수행하기 위한 자체 래퍼를 갖고 사용자가 sftp를 사용하도록 "강제"하려는 경우 명령으로 호출/실행할 수 없기 때문에 이를 가질 수 없으며 internal-sftp내부에 OpenSSH 마법이 있습니다. 실제 사례에서는 rsyncSFTP를 통해 업로드된 모든 파일이 SFTP 세션이 끝날 때 자동으로 미러링되기를 원하므로 이를 사용할 수 없지만 하위 시스템의 기본값을 internal-sftp사용해야 하며 sftpchroot를 수동으로 채우고 호출 /usr/libexec/sftp-server(또는 임의의 다른 경로) 및 rsync마지막 후속 sftp-server실행.

맹목적으로 조언을 따르기보다는 매뉴얼 페이지를 읽어서 뒤에서 무슨 일이 일어나고 있는지 이해해야 합니다.

관련 정보