
내 서버에서 루트 사용자가 액세스할 수 있도록 sftp를 구성하고 싶습니다.
구성을 다음과 같이 변경했습니다 /etc/ssh/sshd_config
.
PermitRootLogin yes
AuthorizedKeysFile .ssh/authorized_keys
PermitEmptyPasswords yes
ChallengeResponseAuthentication no
Compression no
ClientAliveInterval 15
ClientAliveCountMax 4
#Other options are commented
[...]
Subsystem sftp /usr/libexec/sftp-server
Match user root
ChrootDirectory /
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
작동하고 sftp를 통해 내 서버에 연결할 수 있지만 이제 더 이상 ssh를 통해 연결할 수 있습니다. 다음 메시지를 받았습니다.
This service allows sftp connections only.
같은 일이 일어난다Match group root
루트를 허용하면서 ssh도 유지하도록 sftp를 어떻게 구성할 수 있나요?
업데이트:
ForceCommand 내부 sftp 옵션 ssh에 대한 설명은 여전히 작동하지만 sftp로 연결할 수 없습니다. sshd_config:Subsystem sftp /usr/libexec/sftp-server
Match user root
ChrootDirectory /
X11Forwarding no
AllowTcpForwarding no
#ForceCommand internal-sftp
오류:
user@notebook:~$ sftp root@my_device
Warning: the ECDSA host key for 'my_device' differs from the key for the IP address 'xx.xx.xx.xx'
Offending key for IP in /home/myUser/.ssh/known_hosts:78
Matching host key in /home/myUer/.ssh/known_hosts:93
Are you sure you want to continue connecting (yes/no)? yes
Connection closed.
Connection closed
서버 측에서:
root@my_device:~# cat /var/log/auth.log | grep ssh
2024-01-17T19:25:21.659884+00:00 my_device sshd[30592]: Accepted none for root from xx.xx.xx.xx port 38024 ssh2
2024-01-17T19:25:21.881328+00:00 my_device sshd[30592]: Received disconnect from xx.xx.xx.xx port 38024:11: disconnected by user
2024-01-17T19:25:21.881997+00:00 my_device sshd[30592]: Disconnected from user root xx.xx.xx.xx port 38024
Subsystem sftp /usr/libexec/sftp-server
참고: SFTP로 연결하려고 할 때 다른 오류가 발생하여 제거하는 경우 :subsystem request failed on channel 0
답변1
이 ForceCommand
지시문은 루트가 sftp만 사용하도록 허용합니다. 해당 행을 주석 처리해 보세요.
답변2
OpenSSH 매뉴얼 페이지sshd_config(5)이것을 설명합니다 :
ForceCommand
클라이언트가 제공한 모든 명령(~/.ssh/rc
있는 경우 )을 무시하고 에서 지정한 명령을 강제로 실행합니다 . 명령은 옵션과 함께 사용자의 로그인 셸을 사용하여 호출됩니다-c
. 이는 셸, 명령 또는 하위 시스템 실행에 적용됩니다. 블록 내에서 가장 유용합니다Match
. 클라이언트가 원래 제공한 명령은SSH_ORIGINAL_COMMAND
환경 변수에서 사용할 수 있습니다. 의 명령을 지정하면internal-sftp
와 함께 사용할 때 지원 파일이 필요하지 않은 프로세스 내 SFTP 서버를 강제로 사용하게 됩니다ChrootDirectory
. 기본값은 입니다none
.
여기에 설명된 대로 ForceCommand internal-sftp
SFTP만 허용됩니다.
뿐만 아니라,PermitRootLogin yes
루트에 대한 비밀번호 인증을 활성화하므로 위험합니다.ChrootDirectory /
실제로는 제한이 아닙니다chroot 감옥조금도. 다음을 권장합니다.
- 로그인 에 공개 키 인증을 사용
root
하거나root
로그인을 모두 비활성화합니다. - 직접 로그인
sudo
대신 사용root
sudo
권한이 있는 모든 사용자에 대해 공개 키 인증을 사용합니다.- 암호를 사용하십시오
sudo
(이전 암호와 함께 에스컬레이션된 권한에 대한 사실상 MFA임).
서버 오류는 비즈니스 환경과 관련된 질문에 대한 것이며 현재 구성은 이러한 맥락에서 합리적인 관행을 보여주지 않기 때문에 이를 계속 상기시켜 드립니다.
답변3
SSH 구성을 확인하고 보안 SSH 구성을 생성하는 이 Ansible 플레이북을 실행해 볼 수 있습니다. https://github.com/dev-sec/ansible-collection-hardening/tree/master/roles/ssh_hardening
이것을 실행한 후 sshd_config에서 루트 로그인만 허용하면 ssh와 sftp가 모두 작동합니다.
답변4
글쎄, 여기서 문제는 /usr/libexec/sftp-server
서버 측에 존재하지 않는다는 것입니다. 새로운 Yocto 빌드를 사용하여 이미지에 추가한 다음 기본 구성을 사용하여 루트로 ssh 및 sftp로 연결할 수 있었습니다.
# override default of no subsystems
Subsystem sftp /usr/libexec/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server