루트가 아닌 사용자를 사용하여 SSH를 통해 Rsync 데몬 보호

루트가 아닌 사용자를 사용하여 SSH를 통해 Rsync 데몬 보호

불행히도 내 호스팅 공급자로 인해 rsync 데몬에 루트로 액세스하여 이에 따라 보안을 설정할 수 없습니다. 대신, 서버에서 정기적인 원격 백업을 수행하려면 파일을 통해 제한된 sudo 권한을 가진 루트가 아닌 사용자로 rsync 데몬에 액세스해야 합니다 /etc/sudoers.

나는 그것을 작동시켰고 아래 솔루션을 사용하여 성공적으로 백업할 수 있었습니다(아래로 스크롤). 각 요청에 대한 추가 정보
a.) non-root-username다음을 통해 sudo 권한을 얻습니다 /etc/sudoers.

non-root-username ALL=NOPASSWD: /usr/bin/rsync

b.) 목표는 루트가 아닌 사용자를 사용하여 내 시스템 디렉터리의 안전한 원격 백업을 만드는 것입니다 /backups(리소스를 절약하기 위해 rsync 프로토콜 대신 암호화된 SSH 연결 및 rysncd 사용).

c.) 다음 디렉터리 /backups(아래 솔루션은 성공적으로 작동했습니다. 최대한 안전한지 확인하고 싶었습니다.)

질문:
루트가 아닌 rsync 데몬 연결을 더욱 안전하게 만들려면 어떻게 해야 합니까?

질문
sudo rsync환경 변수를 저장하지 않아 다양한 문제가 발생합니다.

1.) /etc/rsyncd.conf 기능 이 hosts allow =더 이상 작동하지 않으면 서버 측 rsync.log에 다음이 표시됩니다.

rsync allowed access on module data from UNKNOWN (0.0.0.0)
rsync on data/ from root@UNKNOWN (0.0.0.0)
building file list

2.) 실제 rsync 명령을 실행하기 위해 각각 via /etc/ssh/sshd_config및/또는 /home/non-root-user/.ssh/authorized_keysI를 사용할 수 없습니다 . 그렇게 하려고 하면 다음과 같은 결과가 발생합니다.ForceCommandcommand=rsync --server --daemon .

rsync: did not see server greeting
rsync error: error starting client-server protocol (code 5) at main.c(1675) [Receiver=3.1.3]

2a.) 현재 루트가 아닌 백업 사용자를 제한하는 이러한 값이 있습니다 /etc/ssh/sshd_config. 다른 제안 사항이 있습니까?

Match User non-root-username
    X11Forwarding no
    AllowTcpForwarding no
    PermitTTY no
   # ForceCommand /usr/bin/sudo /usr/bin/rsync <-- will not work
   # ForceCommand sudo rsync <-- will not work
   # ForceCommand rsync <-- will not work

내 현재 솔루션:

사용:
rsync -a -e "ssh -l non-root-username" --rsync-path="sudo rsync" xx.xx.xx.xx::data /local/path
고쳐 쓰다:
위 명령을 편집하면 가 발생하므로 위의 인증 사용자를 다음 으로 @ERROR: auth failed on module data변경해야 했습니다./etc/rsyncd.confauth users: root/etc/rsyncd.conf

root@admin:~# cat /etc/rsyncd.conf 
# Global configuration of the rsync service
pid file = /var/run/rsyncd.pid
#hosts allow = 123.123.123.123  <-- hashed out
log file = /var/log/rsync.log
# Username and group for working with backups
uid = root
gid = root
# Don't allow to modify the source files
read only = yes
# Data source information
[data]
use chroot = false
#strict modes = false <-- (defaults to true)
path = /backups
list = yes
auth users = root
secrets file = /etc/rsyncd.passwd

내 것에는 /etc/rsyncd.passwd file다음이 있습니다.

root@admin:~# cat /etc/rsyncd.passwd 
root:password

나에게는 다음과 같은 권한이 있습니다 /etc/rsyncd.conf.

root@admin:~# stat /etc/rsyncd.conf 
  File: /etc/rsyncd.conf
  Size: 471         Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 144028      Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: ( 1001/root)
Access: 2022-05-21 13:38:46.797769245 +0800
Modify: 2022-05-21 13:38:42.641735637 +0800
Change: 2022-05-21 13:55:52.384894170 +0800

그리고 나에게는 이러한 권한이 있습니다./etc/rsyncd.passwd

root@admin:~# stat /etc/rsyncd.passwd 
  File: /etc/rsyncd.passwd
  Size: 31          Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 144040      Links: 1
Access: (0640/-rwxrwxr-x)  Uid: (    0/    root)   Gid: ( 1001/root)
Access: 2022-05-21 13:38:06.989448597 +0800
Modify: 2022-05-21 13:37:37.473212811 +0800
Change: 2022-05-21 13:37:37.473212811 +0800

어떤 팁이 있나요?

관련 정보