Showing posts with label File System. Show all posts
Showing posts with label File System. Show all posts

Monday, April 13, 2015

Recursively Find All Files With Only One Line Of Text On Linux

A nice one-liner for finding files that only contain a single line of text which is often the case with Wordpress exploits.
find . -type f -print0 | xargs -0 wc -l | awk '$1==1{print $2}'
...an alternate version:
find . -type f -exec sh -c '[ 1 -eq $(wc -l {}|cut -d" " -f1) ] && echo {}' \;

Wednesday, July 2, 2014

How To Fix Permissions On Home Directory

This will ensure the user and group match the username in /home (non-recursively)
for i in `ls`; do { chown $i:$i $i; }; done;

Thursday, February 7, 2013

Increase The Size Of securetmp In cPanel

First stop all services that might be accessing /tmp:
/etc/init.d/cpanel stop
/etc/init.d/httpd stop
/etc/init.d/mysql stop
Next, unmount /tmp from the current secured mount:
umount -l /tmp
umount -l /var/tmp
Next, backup the current secured mount:
mv /usr/tmpDSK /usr/tmpDSK_back
Next, edit:
/scripts/securetmp
...and change the variable for $tmpdsksize to what size you want, in kilobytes

Next, run the securetmp script:
/scripts/securetmp
Finally, restart the services stopped previously:
/etc/init.d/cpanel start
/etc/init.d/httpd start
/etc/init.d/mysql start
You can confirm the size of /tmp by checking the output of:
df -h

Thursday, December 20, 2012

Find User With Most Diskspace Used Using Linux Quotas

This will show the entire quota table sorted in descending order:
repquota  -a  | grep '\-\- ' | sort -rn -k 3 | more

If you aren't running quotas, you can still find the user by going into /home and using:
du -m --max-depth=1 | sort -rn

The results will be in MegaBytes. Note that using this method can take a long time to run on larger filesystems with many users.

Tuesday, October 30, 2012

Securing /tmp And /var/tmp On DirectAdmin With SecureTmp

This presumes you are using a fresh server with no valuable contents in /tmp or /var/tmp. This still applies even if you do, just make a backup of the directory contents so it can be restored after.

This will give you ~2.1GB of /tmp and /var/tmp
dd if=/dev/zero of=/var/varTmp bs=1024 count=2048000
dd if=/dev/zero of=/var/Tmp bs=1024 count=2048000
/sbin/mkfs -t ext3 /var/varTmp
/sbin/mkfs -t ext3 /var/Tmp
mount -o loop,noexec,nosuid,rw /var/Tmp /tmp
mount -o loop,noexec,nosuid,rw /var/varTmp /var/tmp
chmod 0777 /tmp
chmod +t /tmp
chmod 0777 /var/tmp
chmod +t /var/tmp

Add to /etc/fstab:
/var/Tmp        /tmp            ext3    loop,noexec,nosuid,rw   0       0
/var/varTmp     /var/tmp        ext3    loop,noexec,nosuid,rw   0       0

You may want to reboot =)

Tuesday, October 2, 2012

Enable SPF On All cPanel Accounts

for i in `ls /var/cpanel/users/`;do /usr/local/cpanel/bin/spf_installer $i ;done

Enable DKIM On All cPanel Accounts

for i in `ls /var/cpanel/users` ;do /usr/local/cpanel/bin/dkim_keys_install $i ;done

Friday, September 21, 2012

Access Or Rename Folders Named With Control Characters

Sometimes when cleaning up systems that have been compromised you end up with folders that have been created with control characters making it seemingly impossible to enter or rename them.

The easiest method here is to rename them by referencing the INODE number of the system.

First we get the inode number:
root@server [/]# ls -il
 96372062 drwxr-xr-x  2 root root  4096 Jan 01  2000 \t\t\t\t/
Now that we know the inode number, 96372062, we can rename it using find and move:
root@server [/]# find . -type d -inum 96372062 -exec mv -i {} delete-me \;
This essentially looks for all directories in the current directory (recursively) with the inode specified and then asks (-i is interactive mode) to move that directory to a new name of "delete-me".

This is extremely handy, however, always exercise caution.

Thursday, September 20, 2012

.htaccess pcfg_openfile on cPanel With suPHP

On cPanel running suPHP the entire contents of the users public_html folder need to be 755 so:
[/home/$user/public_html]# chmod -R 755 *
Now, you may have to do this explicitly on the .htaccess file(s) as well
[/home/$user/public_html]# chmod 755 .htaccess
If you are still having issues you can:
[/etc/httpd/logs]# tail -f error_log
...to see what errors you are getting

Monday, November 14, 2011

Monday, October 3, 2011

How To Exclude Multiple Directories From Tar

This assumes you are working in /

tar cvzf [/path/to/store/file.tgz] --exclude ./exclude1 --exclude ./exclude2 [/path/to/tar/up]

Saturday, December 18, 2010

Find And Delete All Files Owned By A User In The Current Directory

find . -user $username -delete
Some older versions of find don't support -delete so instead use:
find . -user $username -exec rm -rf {} \;

Tuesday, February 2, 2010

Recursively copy specific files/extension from current folder down to another folder

//COPY ALL TAR.GZ FILES FROM CURRENT AND LOWER TO /HOME/
find . -name \*.tar.gz  -exec cp '{}' /home/  \;

...in this case copy all .tar.gz files from the current directory to /home/

Monday, January 25, 2010

Recursive file/folder tree

<?php
function create_tree($dir)
{
 if ($handle = @opendir($dir))
 {
  $i=0;
  while (false !== ($file = @readdir($handle)))
  {
   if ($file != '.' && $file != '..')
   {
   $list[$i]=$file;
   $i++;
   }
  }
  $dir_length = count($list);

  for($i=0;$i<$dir_length;$i++)
  {
   if(strrpos($list[$i], '.') == FALSE)
   {
    echo '
  • '.$list[$i].'
      '; create_tree($dir.'/'.$list[$i]); echo '
  • '; } else { echo '
  • '.$list[$i].'
  • '; /* I REALIZE THE HREF ATTRIBUTE ABOVE LOOKS QUOTED WEIRD BLOGGER KEEPS OVERRIDING NESTED QUOTES FOR SOME REASON */ } } closedir($handle); } } $dir = '/'; echo '
      '.dirname($dir).'
    • '.basename($dir).'
        '; create_tree($dir); echo '
    '; ?>