银河麒麟高级服务器操作系统通用rsync禁止匿名访问操作指南
- 一 系统环境
- 二、基础信息
- 2.1 IP信息
- 2.2 两台机器分别执行关闭firewalld或者放行相关的端口
- 三、服务端配置
- 3.1 配置rsync.conf文件
- 3.2 创建密码文件
- 3.3 重启rsyncd 服务
- 四、客户端测试
- 4.1 allowed_user1和allowed_user2用户测试
- 4.2 其他用户测试
一 系统环境
#本文采用V10SP2进行演示
[root@localhost ~]# nkvers
############## Kylin Linux Version #################
Release:
Kylin Linux Advanced Server release V10 (Sword)
Kernel:
4.19.90-25.35.v2101.ky10.x86_64
Build:
Kylin Linux Advanced Server
release V10 (SP2) /(Sword)-x86_64-Build09/20210524
#################################################
二、基础信息
2.1 IP信息
准备两台虚拟机,一台当做服务端,一台当做客户端
服务端IP:172.16.211.131
客户端IP:172.16.211.129
2.2 两台机器分别执行关闭firewalld或者放行相关的端口
systemctl disable firewalld --now
三、服务端配置
3.1 配置rsync.conf文件
打开 /etc/rsyncd.conf,检查所有模块配置(如 [public] 或自定义模块),确保不允许匿名访问:
以下示例是添加一个新的共享目录
[anon]
path = /path/to/anon
# 以下为关键安全配置
auth users = allowed_user1,allowed_user2 # 指定允许访问的用户列表
secrets file = /etc/rsyncd.secrets # 指定存储用户密码的文件
read only = yes # 设置为 yes 时禁止写入(根据需求调整)
list = no # 禁止匿名用户查看模块列表
3.2 创建密码文件
生成 /etc/rsyncd.secrets 并设置权限:
echo "allowed_user1:password1" >> /etc/rsyncd.secrets
echo "allowed_user2:password2" >> /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets
3.3 重启rsyncd 服务
systemctl restart rsyncd
四、客户端测试
4.1 allowed_user1和allowed_user2用户测试
[kylin@localhost ~]$ rsync rsync://allowed_user1@172.16.211.131:/anon
Password:
@ERROR: auth failed on module anon
rsync error: error starting client-server protocol (code 5) at main.c(1659) [Receiver=3.1.3]
[kylin@localhost ~]$ rsync rsync://allowed_user1@172.16.211.131:/anon
Password:
drwxr-xr-x 32 2025/02/25 09:14:20 .
-rw-r--r-- 0 2025/02/25 09:14:18 1.txt
-rw-r--r-- 0 2025/02/25 09:14:20 2.txt
[kylin@localhost ~]$
[kylin@localhost ~]$
[kylin@localhost ~]$
[kylin@localhost ~]$ rsync rsync://allowed_user2@172.16.211.131:/anon
Password:
drwxr-xr-x 32 2025/02/25 09:14:20 .
-rw-r--r-- 0 2025/02/25 09:14:18 1.txt
-rw-r--r-- 0 2025/02/25 09:14:20 2.txt
4.2 其他用户测试
[kylin@localhost ~]$ rsync rsync://allowed_user3@172.16.211.131:/anon
Password:
@ERROR: auth failed on module anon
rsync error: error starting client-server protocol (code 5) at main.c(1659) [Receiver=3.1.3]
经过以上测试发现,允许目录中的allowed_user1、allowed_user2用户可以正常访问,不在允许目录中的allowed_user3用户无法正常访问。