DEV Community

Ashish-Chorge
Ashish-Chorge

Posted on Edited on

Build an SFTP server for VCF backups

A step-by-step procedure for building a hardened, SFTP-only backup target, creating the per-instance folder layout, and connecting SDDC Manager, NSX, vCenter, VCF management services and VCF Automation to it

0. Ubuntu/RHEL Linux server build & storage layout

Reference partition structure

a. Prepare the backup data disk after the OS install. Confirm the device name first; this wipes the disk.

lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT          # confirm /dev/sdb is the empty 500 GB-1 TB disk
sudo pvcreate /dev/sdb
sudo vgcreate vg_backup /dev/sdb
sudo lvcreate -n lv_backup -l 100%FREE vg_backup
sudo mkfs.xfs /dev/vg_backup/lv_backup

sudo mkdir -p /srv/sftp
echo '/dev/mapper/vg_backup-lv_backup /srv/sftp xfs defaults,nodev,nosuid,noexec 0 0' | sudo tee -a /etc/fstab
sudo systemctl daemon-reload && sudo mount -a
sudo chown root:root /srv/sftp && sudo chmod 755 /srv/sftp   # chroot base must be root-owned after mounting
sudo restorecon -Rv /srv/sftp
df -h /srv/sftp
Enter fullscreen mode Exit fullscreen mode

b. To grow the volume later (online, no downtime), increase Disk 2 in vCenter, then on the server:

echo 1 | sudo tee /sys/class/block/sdb/device/rescan   # detect the new VMDK size
lsblk /dev/sdb
sudo pvresize /dev/sdb
sudo lvextend -r -l +100%FREE /dev/vg_backup/lv_backup          # -r grows XFS in the same step
df -h /srv/sftp

# Alternative: add another VMDK instead of growing the existing one
# sudo pvcreate /dev/sdc && sudo vgextend vg_backup /dev/sdc
# sudo lvextend -r -l +100%FREE /dev/vg_backup/lv_backup
Enter fullscreen mode Exit fullscreen mode

Linux will not enlarge the disk by itself. This layout makes growth an online, non-disruptive operation. Set a capacity alert, for example at 80% (step 10), and grow Disk 2 when it fires. If the customer wants growth to be hands-free, their automation can run the same steps when the alert triggers.

1. Install OpenSSH

Why SFTP is a subsystem of the OpenSSH server, so there is no separate SFTP product to install. On RHEL 9, OpenSSH follows the system-wide crypto policy, which already disables weak algorithms.

sudo dnf update -y
sudo dnf install -y openssh-server firewalld policycoreutils-python-utils
sudo systemctl enable --now sshd firewalld
sudo systemctl status sshd --no-pager
ssh -V     # note the OpenSSH version; it matters in step 05
Enter fullscreen mode Exit fullscreen mode

On another distribution, install and enable that distribution's supported OpenSSH server package. Reference: Red Hat: RHEL 9 OpenSSH secure communications.

2. Verify host keys & algorithms

VCF pins the server's SSH host fingerprint and negotiates specific algorithms. If the server cannot offer them, the VCF configuration fails at fingerprint retrieval or first backup, which is harder to diagnose.

sudo ssh-keygen -A                                   # create any missing host keys
sudo ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub    # expect 2048+ bits, SHA256 fingerprint
sudo ssh-keygen -lf /etc/ssh/ssh_host_ecdsa_key.pub  # expect 256+ bits
sudo ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
sudo sshd -T | grep -Ei '^(hostkeyalgorithms|kexalgorithms|macs|ciphers) '
Enter fullscreen mode Exit fullscreen mode

Caution
Do not regenerate host keys on a server that is already in use. That changes the fingerprint every VCF component trusts. Do not loosen the OS crypto policy globally to make a test pass; raise any gap with the customer security team.

3. Create the SFTP account & chroot

A dedicated, non-interactive account confined to one directory keeps the blast radius small. VCF only needs file transfer, not a shell.

sudo useradd --no-create-home --home-dir / --shell /sbin/nologin svc-vcf-bck
sudo passwd svc-vcf-bck        # paste the vaulted password; never script it

sudo mkdir -p /srv/sftp/svc-vcf-bck/backups
sudo chown root:root /srv/sftp /srv/sftp/svc-vcf-bck
sudo chmod 755 /srv/sftp /srv/sftp/svc-vcf-bck
sudo chown svc-vcf-bck:svc-vcf-bck /srv/sftp/svc-vcf-bck/backups
sudo chmod 750 /srv/sftp/svc-vcf-bck/backups

namei -l /srv/sftp/svc-vcf-bck/backups   # every parent: root-owned, not group/other writable
Enter fullscreen mode Exit fullscreen mode

OpenSSH refuses a chroot whose path components are writable by anyone other than root. Only backups is writable by the service account. If SELinux is enforcing, keep it enforcing and read ausearch -m avc -ts recent on denials.

4. Restrict the account to SFTP

internal-sftp with ChrootDirectory blocks shell, tunnelling and access outside the backup tree, while VCF can still read and write files.

a. Back up the current configuration and keep your admin session open until testing is complete

sudo cp -a /etc/ssh/sshd_config /etc/ssh/sshd_config.pre-vcf-sftp
Enter fullscreen mode Exit fullscreen mode

b. Only if OpenSSH is 9.8 or later (RHEL 9 ships 8.7): Broadcom requires exempting the SDDC Manager and NSX Manager IPs from per-source penalties. This is a global option, so place it above any Match block.

PerSourcePenaltyExemptList 192.0.2.21,192.0.2.31,192.0.2.32,192.0.2.33
Enter fullscreen mode Exit fullscreen mode

c. Append this block to the end of /etc/ssh/sshd_config. Everything after a Match line applies only to that match.

Match User svc-vcf-bck
    ChrootDirectory /srv/sftp/%u
    ForceCommand internal-sftp -d /backups
    PasswordAuthentication yes
    AllowTcpForwarding no
    X11Forwarding no
    PermitTTY no
Enter fullscreen mode Exit fullscreen mode

d. Validate, then reload. Do not reload if sshd -t prints an error.

sudo sshd -t && sudo systemctl reload sshd
sudo systemctl status sshd --no-pager
Enter fullscreen mode Exit fullscreen mode

5. Restrict network access

ackup data contains configuration and secrets for the whole platform. Only VCF appliances that write backups should reach the SFTP port.

Source IPs used below: 192.0.2.21 192.0.2.31 192.0.2.32 192.0.2.33 192.0.2.11 192.0.2.41. Update them in Your values.

sudo firewall-cmd --get-active-zones
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.0.2.21" port port="22" protocol="tcp" accept'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.0.2.31" port port="22" protocol="tcp" accept'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.0.2.32" port port="22" protocol="tcp" accept'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.0.2.33" port port="22" protocol="tcp" accept'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.0.2.11" port port="22" protocol="tcp" accept'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.0.2.41" port port="22" protocol="tcp" accept'
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
Enter fullscreen mode Exit fullscreen mode

Caution
Rich rules only restrict access if the zone does not also allow the ssh service to everyone. Remove the broad service with firewall-cmd --permanent --remove-service=ssh only after admin access from an allowed source is confirmed. Otherwise you can lock yourself out.

Custom port: set Port in sshd_config, then run sudo semanage port -a -t ssh_port_t -p tcp 22, and use the same port in every VCF screen. VCF 9.1.1 and later support a custom SFTP port.

6. Create the VCF folder structure

A consistent per-instance and per-domain layout keeps backups from different VCF instances and domains apart, which makes restores and retention cleanup predictable.

#!/usr/bin/env bash
set -euo pipefail

# Usage:
#   bash create_vcf_sftp_backup_dirs.sh [backup-root]
# Example:
#   bash create_vcf_sftp_backup_dirs.sh /srv/sftp/backups/VCF
#
# Add the actual workload-domain names to the arrays below before running.
# Example: INST1_WORKLOAD_DOMAINS=("INST1-WLD01" "INST1-WLD02")

BACKUP_ROOT="${1:-/backups/VCF}"

INST1_WORKLOAD_DOMAINS=()
INST2_WORKLOAD_DOMAINS=()
INST3_WORKLOAD_DOMAINS=()
INST4_WORKLOAD_DOMAINS=()

create_instance() {
    local instance="$1"
    shift
    local -a workload_domains=("$@")
    local instance_root="${BACKUP_ROOT%/}/${instance}"

    mkdir -p \
        "${instance_root}/Management-Domain/SDDC-Manager" \
        "${instance_root}/Management-Domain/vCenter" \
        "${instance_root}/Management-Domain/NSX-Manager" \
        "${instance_root}/Management-Domain/VCF-Management-Services" \
        "${instance_root}/Management-Domain/VCF-Automation" \
        "${instance_root}/Workload-Domains"

    local domain
    for domain in "${workload_domains[@]}"; do
        if [[ -z "${domain}" || "${domain}" == */* || "${domain}" == "." || "${domain}" == ".." ]]; then
            printf 'Error: invalid workload-domain name: %q\n' "${domain}" >&2
            return 1
        fi
        mkdir -p \
            "${instance_root}/Workload-Domains/${domain}/vCenter" \
            "${instance_root}/Workload-Domains/${domain}/NSX-Manager"
    done

    printf 'Created directory structure for %s under %s\n' "${instance}" "${instance_root}"
}

create_instance INST1 "${INST1_WORKLOAD_DOMAINS[@]}"
create_instance INST2 "${INST2_WORKLOAD_DOMAINS[@]}"
create_instance INST3 "${INST3_WORKLOAD_DOMAINS[@]}"
create_instance INST4 "${INST4_WORKLOAD_DOMAINS[@]}"
Enter fullscreen mode Exit fullscreen mode

Resulting layout · per instance (INST1, INST2, INST3, INST4)
/backups/VCF/INST1/
├── Management-Domain/
│ ├── SDDC-Manager/
│ ├── vCenter/
│ ├── NSX-Manager/
│ ├── VCF-Management-Services/
│ └── VCF-Automation/
└── Workload-Domains/
└── <workload-domain>/
├── vCenter/
└── NSX-Manager/

7. Test before VCF

Prove login, chroot, write and delete with a normal SFTP client first. Then any failure in VCF is a VCF-side issue, not a server issue.

a. From an admin workstation or jump host on the management network:

sftp -P 22 svc-vcf-bck@vcf-sftp.example.net
Enter fullscreen mode Exit fullscreen mode

b. At the sftp> prompt, verify the chroot, write and delete:

pwd                       # expect /backups
ls /backups/VCF/INST1/Management-Domain
put /etc/hostname /backups/VCF/INST1/Management-Domain/SDDC-Manager/smoke-test.txt
ls -l /backups/VCF/INST1/Management-Domain/SDDC-Manager
rm /backups/VCF/INST1/Management-Domain/SDDC-Manager/smoke-test.txt
cd /etc                   # expect: no such file or directory
bye
Enter fullscreen mode Exit fullscreen mode

c. Confirm that shell access is refused, and record the trusted fingerprint to compare in VCF:

ssh -p 22 svc-vcf-bck@vcf-sftp.example.net               # expect: only SFTP allowed / connection closed
ssh-keyscan -p 22 -t rsa vcf-sftp.example.net 2>/dev/null | ssh-keygen -lf -
sudo ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub      # run on the SFTP host; both must match
Enter fullscreen mode Exit fullscreen mode

Top comments (0)