OpenBSD Handbook

    Theme
    • Part I. Install & Configure
      • Introduction to OpenBSD
      • Installing OpenBSD
      • The X Window System
      • Networking on OpenBSD
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • OpenBSD Desktop Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
      • Security
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • Pure-FTPd
          • TFTP
        • Mail
          • OpenSMTPD Mail Server
          • Dovecot IMAP and POP3 Server
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Unbound DNS Resolver
          • NSD Authoritative DNS Server
          • BIND DNS Server
        • Networking
          • OpenBGPD
          • rad
          • DHCP on OpenBSD
          • slaacd
        • Web
          • Apache HTTP Server
          • nginx Web Server
          • OpenBSD httpd Web Server
          • relayd Reverse Proxy
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • OpenSSH Server
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ Message Broker
        • Time
          • NTP Time Synchronization
        • Load Balancing
          • Build Redundant Load-Balanced Gateways
          • Load Balance Services with NAT or DSR
          • Build an HA HTTPS Load Balancer
      • PF
        • pfctl cheat sheet
        • PF Anchors
        • PF Filter Rules
        • PF Forwarding
        • PF Lists and Macros
        • PF Load Balancing
        • PF Logging
        • PF NAT
        • PF Options
        • PF Policies
        • PF Shortcuts
        • PF Tables
      • Advanced Networking
        • High Availability and State Replication
        • Multi-WAN and Policy-Based Routing
        • VPN and Cryptographic Tunneling
        • Classic and Lightweight Tunnels
        • IPv6 at Scale
        • QoS and Traffic Shaping
        • MPLS and Label Distribution
        • Network Services at Scale
        • Virtualization and Host Networking
        • Large-Scale L2 and L3 Design
        • Telemetry, Logging, and Flow Export
        • Hardening and Operational Safety
        • Reference Architectures
        • Troubleshooting Playbooks
      • Serial Communication
    • Part V. Miscellaneous
      • Virtualization Cheat Sheet
      • OpenBSD Cheatsheet
      • How-to Guides
        • Installation and First Boot
          • Complete the First 30 Minutes After Installation
          • Check Hardware Compatibility Before Installing
          • Bootstrap Wi-Fi Firmware Without Ethernet
          • Run OpenBSD as a Virtual Machine Guest
          • Install OpenBSD on a VPS or Cloud Server
          • Install OpenBSD with Full-Disk Encryption
          • Dual-Boot OpenBSD on a UEFI System
          • Automate OpenBSD Installation with Autoinstall and PXE
        • Desktops and Laptops
          • Set Up OpenBSD as a Laptop or Workstation
          • Configure Laptop Power Management
          • Troubleshoot Web Browsers on OpenBSD
          • Use Plan 9 Tools on OpenBSD
          • Build a Minimal Desktop with suckless Tools
          • Install Z shell (zsh)
        • Networking and Remote Access
          • Create an Administrator Account with doas and SSH Keys
          • Configure Secure Remote Access with OpenSSH
          • Use FIDO Security Keys with OpenSSH
          • Configure Wi-Fi Roaming and Wired Failover
          • Troubleshoot PF, NAT, and Routing
          • Route Multiple VLANs with PF
          • Configure a Road-Warrior WireGuard VPN
          • Route IPv6 Networks without NAT
          • Test OpenBGPD with Two Providers
          • Unlock an Internal Service with an SSH Key
          • Build a Simple Router and Firewall
        • Servers and Services
          • Set Up WordPress on OpenBSD
          • Build a Mail Server with OpenSMTPD, Dovecot, and Rspamd
        • Security, Maintenance and Recovery
          • Establish a Conservative Security Baseline
          • Recover Access and Reset the Root Password
          • Collect OpenBSD Diagnostic Evidence
          • Troubleshoot Package Installation and Update Failures
          • Schedule Recurring Maintenance
          • Monitor an OpenBSD System
          • Back Up and Restore an OpenBSD System
          • Configure softraid RAID1
          • Recover an OpenBSD System That Does Not Boot
        • Building, Automation and Virtual Machines
          • Manage OpenBSD with Ansible
          • Build Third-Party Software from Ports
          • Build OpenBSD from Source
          • Plan a Docker Workload Migration to OpenBSD
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • OpenBSD FAQ
    • OpenBSD Architectures
      • OpenBSD Package Search
        • Synopsis
        • Installation
        • Client Usage
          • Syntax
          • Local Copy
          • Remote Copy Over SSH
          • Exclude Files
          • Deleting Removed Files
          • Dry Run
        • Running an rsync Server
          • rsyncd Configuration
          • Authentication Secrets
          • Starting the Daemon
        • Connecting to an rsync Daemon
        • Comparison with Alternatives
        • Security Considerations
        • Summary of Common Commands

        rsync

        Synopsis #

        rsync synchronizes files and directories between local or remote systems, transferring changed data to reduce repeated copying. Install it from packages and use ssh(1) for encrypted remote transfers. It can also serve files through a standalone daemon; that protocol does not encrypt traffic.

        Installation #

        To install rsync from the OpenBSD packages collection:

        doas pkg_add rsync
        

        This installs the rsync binary and associated files to /usr/local/bin/rsync.

        Client Usage #

        The most common use case for rsync is as a client to synchronize files to or from a local or remote system. It supports multiple transports, with ssh(1) being the default for remote operations.

        Syntax #

        rsync [options] SOURCE DEST
        

        Local Copy #

        To copy a directory locally:

        rsync -av /home/user/documents/ /backup/documents/
        
        • -a: Archive mode (preserves permissions, symlinks, etc.)
        • -v: Verbose output
        • Trailing slash in source ensures contents are copied, not the directory itself.

        Remote Copy Over SSH #

        To copy files to a remote host over SSH:

        rsync -avz /home/user/data/ user@remote.example.com:/home/user/backup/
        

        To copy from a remote host:

        rsync -avz user@remote.example.com:/var/log/ ./logs/
        
        • -z: Enable compression
        • -e ssh: Can be omitted; rsync defaults to SSH transport

        To specify a non-standard SSH port:

        rsync -av -e "ssh -p 2222" ./site/ user@remote.example.com:/var/www/
        

        Exclude Files #

        Exclude temporary files:

        rsync -av --exclude '*.tmp' src/ user@host:/srv/
        

        To exclude a list of patterns:

        rsync -av --exclude-from=exclude.txt src/ user@host:/srv/
        

        Deleting Removed Files #

        Synchronize and delete files on the destination not present in the source:

        rsync -av --delete ./syncdir/ user@host:/srv/syncdir/
        

        Dry Run #

        Preview the changes without making them:

        rsync -av --dry-run ./docs/ user@host:/backup/docs/
        

        Running an rsync Server #

        rsync can be run as a standalone daemon to provide files over the rsync:// protocol. Unlike typical SSH-based usage, this mode does not use SSH and requires explicit configuration and activation.

        rsyncd Configuration #

        When running as a daemon, rsync reads its configuration from /etc/rsyncd.conf, or another file specified via the --config option. The format resembles an INI file, with one or more modules defined.

        Example configuration:

        uid = _rsync
        gid = _rsync
        use chroot = yes
        max connections = 4
        log file = /var/log/rsyncd.log
        pid file = /var/run/rsyncd.pid
        
        [public]
            path = /srv/rsync/public
            comment = Public files
            read only = yes
            list = yes
        
        [backup]
            path = /srv/rsync/private
            comment = Backup files
            auth users = backupuser
            secrets file = /etc/rsyncd.secrets
            read only = no
            list = no
        

        This example defines two modules:

        • public: A read-only public directory.
        • backup: A password-protected writable module restricted to backupuser.

        Authentication Secrets #

        If any module uses auth users, a secrets file must be specified. This file maps usernames to passwords:

        backupuser:password123
        

        Set secure permissions on the secrets file:

        doas chmod 600 /etc/rsyncd.secrets
        

        Starting the Daemon #

        The package supplies /etc/rc.d/rsyncd. Create both module directories and give _rsync the required access; only the private upload directory needs write access. Confirm the packaged account exists before setting ownership.

        doas mkdir -p /srv/rsync/public /srv/rsync/private
        doas chown _rsync:_rsync /srv/rsync/private
        doas chmod 750 /srv/rsync/private
        doas rcctl enable rsyncd
        doas rcctl start rsyncd
        doas rcctl check rsyncd
        

        Public files must be readable by the daemon identity. Restrict access to the daemon port with PF and test denied authentication as well as a successful transfer.

        Connecting to an rsync Daemon #

        To connect to a public module on an rsync server:

        rsync rsync://rsync.example.com/public/
        

        To synchronize with authentication:

        rsync -av --password-file="$HOME/.rsync.pass" rsync://backupuser@rsync.example.com/backup/ ./backup/
        

        Create ~/.rsync.pass as the invoking user with private permissions; it contains only the password:

        password123
        

        Ensure proper file permissions:

        chmod 600 "$HOME/.rsync.pass"
        

        Comparison with Alternatives #

        ToolEncryptedSuitable ForNotes
        rsyncOptionalLarge file setsDelta transfers; daemon or over SSH
        scpYesSimple copiesAlways encrypted; no resume support
        sftpYesInteractive useSSH-based file transfers
        ftpNoAnonymous accessLegacy; less secure
        httpOptionalPublic downloadsEfficient for static file serving

        Security Considerations #

        • When using the daemon mode (rsync://), no encryption is performed.
        • Always prefer SSH-based rsync for secure transfers.
        • Protect secrets files (rsyncd.secrets, --password-file) with strict permissions.
        • Use chroot, UID/GID restrictions, and appropriate file permissions when exposing rsyncd.

        Summary of Common Commands #

        CommandDescription
        pkg_add rsyncInstall rsync on OpenBSD
        rsync -avz src/ user@host:/dest/Copy with archive mode and compression
        rsync -av --delete src/ user@host:/dest/Sync and delete extraneous files
        rsync -e "ssh -p 2222"Use custom SSH port
        rsync --daemonLaunch rsync server daemon
        rsync rsync://host/module/Connect to a remote rsync daemon
        Report a bug
        • Synopsis
        • Installation
        • Client Usage
          • Syntax
          • Local Copy
          • Remote Copy Over SSH
          • Exclude Files
          • Deleting Removed Files
          • Dry Run
        • Running an rsync Server
          • rsyncd Configuration
          • Authentication Secrets
          • Starting the Daemon
        • Connecting to an rsync Daemon
        • Comparison with Alternatives
        • Security Considerations
        • Summary of Common Commands