{"id":30683,"date":"2021-02-02T19:48:30","date_gmt":"2021-02-02T11:48:30","guid":{"rendered":"https:\/\/web.mwwsb.com.my\/pjci\/?post_type=kb&p=30683"},"modified":"2022-09-08T21:32:55","modified_gmt":"2022-09-08T13:32:55","slug":"script-to-fix-cpanel-account-permissions-2","status":"publish","type":"kb","link":"https:\/\/www.casbay.com\/guide\/kb\/script-to-fix-cpanel-account-permissions-2","title":{"rendered":"Script to Fix cPanel Account Permissions"},"content":{"rendered":"\t\t
\n\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\tThis is a simple bash script to fix the permissions and ownership of files within a cpanel account. To use, simply copy the script your server, chmod 755, and pass the usernames as arguments:\n

\n.\/fixperms user1 user2 user3<\/code>\n

\nYou can also run a server-wide loop like this:\n

\nfor i in `ls -A \/var\/cpanel\/users` ; do .\/fixperms $i ; done<\/code>\n

\nBelow is the script:\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t
#!\/bin\/bash\n# Script to fix permissions of accounts\n\nif [ \"$#\" -lt \"1\" ];then\n  echo \"Must specify user\"\n  exit;\nfi\n\nUSER=$@\n\nfor user in $USER\ndo\n\n  HOMEDIR=$(egrep \"^${user}:\" \/etc\/passwd | cut -d: -f6)\n\n  if [ ! -f \/var\/cpanel\/users\/$user ]; then\n    echo \"$user user file missing, likely an invalid user\"\n  elif [ \"$HOMEDIR\" == \"\" ];then\n    echo \"Couldn't determine home directory for $user\"\n  else\n    echo \"Setting ownership for user $user\"\n    chown -R $user:$user $HOMEDIR\n    chmod 711 $HOMEDIR\n    chown $user:nobody $HOMEDIR\/public_html $HOMEDIR\/.htpasswds\n    chown $user:mail $HOMEDIR\/etc $HOMEDIR\/etc\/*\/shadow $HOMEDIR\/etc\/*\/passwd\n\n    echo \"Setting permissions for user $USER\"\n\n    find $HOMEDIR -type f -exec chmod 644 {} ; -print\n    find $HOMEDIR -type d -exec chmod 755 {} ; -print\n    find $HOMEDIR -type d -name cgi-bin -exec chmod 755 {} ; -print\n    find $HOMEDIR -type f ( -name \"*.pl\" -o -name \"*.perl\" ) -exec chmod 755 {} ; -print\n  fi\n\ndone\n\nchmod 750 $HOMEDIR\/public_html\n\nif [ -d \"$HOMEDIR\/.cagefs\" ]; then\n  chmod 775 $HOMEDIR\/.cagefs\n  chmod 700 $HOMEDIR\/.cagefs\/tmp\n  chmod 700 $HOMEDIR\/.cagefs\/var\n  chmod 777 $HOMEDIR\/.cagefs\/cache\n  chmod 777 $HOMEDIR\/.cagefs\/run\nfi<\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\tCheck out the next article on How To Check the Version of cPanel\/WHM<\/a>.\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"

This is a simple bash script to fix the permissions and ownership of files within a cpanel account. To use, simply copy the script your server, chmod 755, and pass the usernames as arguments: .\/fixperms user1 user2 user3 You can also run a server-wide loop like this: for i in `ls -A \/var\/cpanel\/users` ; do […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"no-sidebar","site-content-layout":"page-builder","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"disabled","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}}},"kbtopic":[117],"kbtag":[106],"mkb_version":[],"_links":{"self":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb\/30683"}],"collection":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/types\/kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/comments?post=30683"}],"version-history":[{"count":7,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb\/30683\/revisions"}],"predecessor-version":[{"id":37433,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb\/30683\/revisions\/37433"}],"wp:attachment":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/media?parent=30683"}],"wp:term":[{"taxonomy":"kbtopic","embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kbtopic?post=30683"},{"taxonomy":"kbtag","embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kbtag?post=30683"},{"taxonomy":"mkb_version","embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/mkb_version?post=30683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}