Skip to content

Instantly share code, notes, and snippets.

@foursixnine
Created October 24, 2026 05:56
Show Gist options
  • Select an option

  • Save foursixnine/ed69e2cd88f009f4881615aea066ce4f to your computer and use it in GitHub Desktop.

Select an option

Save foursixnine/ed69e2cd88f009f4881615aea066ce4f to your computer and use it in GitHub Desktop.
Very empiric setup for allowing an user to push files into a webserver via sftp, with SELinux profile\nMaybe I will blog about this in foursixnine.io

ssh config for sftponly group

# SFTP-only chroot configuration
# Applied to all members of the sftponly group

Match Group sftponly
    ForceCommand internal-sftp
    ChrootDirectory /srv/www/sites/%u
    AllowTcpForwarding no
    X11Forwarding no
    PermitTunnel no
    PermitTTY no
    AllowAgentForwarding no

Selinux policy

allow-sftp.selinux.te

module allow-sftp.selinux 1.0;

require {
	type sshd_session_t;
	type httpd_sys_content_t;
	class dir { getattr search };
	class file { open read };
}

#============= sshd_session_t ==============

allow sshd_session_t httpd_sys_content_t:dir search;
allow sshd_session_t httpd_sys_content_t:dir getattr;

allow sshd_session_t httpd_sys_content_t:file { open read };

allow-sftp.selinux.fc

# File contexts for the allow-sftp SELinux module.
#
# This module assumes an SELinux equivalence rule maps /srv/www/sites to
# /var/www/sites. Keep the canonical policy paths under /var/www/sites so the
# existing equivalence policy continues to work.
#
# Per-user SSH material inside the chroot.
/var/www/sites/[^/]+/\.ssh(/.*)?    gen_context(system_u:object_r:ssh_home_t,s0)
# Published static site content.
/var/www/sites/[^/]+/html(/.*)?      gen_context(system_u:object_r:httpd_sys_content_t,s0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment