Skip to content

Instantly share code, notes, and snippets.

@noize-e
Last active November 7, 2020 08:05
Show Gist options
  • Save noize-e/b32483275ebd183fa4ae8bafe1108ca1 to your computer and use it in GitHub Desktop.
Save noize-e/b32483275ebd183fa4ae8bafe1108ca1 to your computer and use it in GitHub Desktop.
SELinux file context& permissions( 755 ) fixer
#!/bin/bash
#
# Change file or dir permissions mode and, sets SELinux 'httpd_sys_script_exec_t' file context.
# Permissions mode: (u:7) (g:5) (o:5)
# (u) the user who owns it
# (g) other users in the file's group
# (o) other users not in the file's group
#
# Usage: fix_perms {grp-name} {directory|filename}
fix_context() {
mode=755; group="${1}"; dirfile="${2}"
chmod -R $mode $dirfile &&
chown -R $group $dirfile &&
chgrp -R $group $dirfile
# Change the SELinux file context temporary
# chcon --user system_u --type httpd_sys_content_t -R $dirfile
# Change the SELinux file context permanent
semanage fcontext -a -t httpd_sys_script_exec_t $dirfile
# List all files with the security context append
ls -alZ $route
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment