Linux
Everything about Unix and GNU/Linux operating systems.
Everything about Unix and GNU/Linux operating systems.
du command in linux efficientlysudo du -ahx / | sort -rh | head -20-a β Show both files and directories-h β Human-readable sizes (e.g., MB, GB)-x β Stay on the same filesystem (avoid mounted drives)sort -rh β Sort by size, largest firsthead -20 β Show top 20 largest directories/filessudo du -hx --max-depth=3 / | sort -rh | head -20--max-depth=3 β Limits output to top 3 levels for better readabilitysudo find / -type f -size +500M -exec du -h {} + | sort -rh | head -20-type f β Only files-size +500M β Files larger than 500MBdu -h β Show file sizes in human-readable formatsudo du -ahx --exclude={/proc,/sys,/dev,/run,/snap,/tmp,/mnt,/media} / | sort -rh | head -20sudo du -sh /home/* 2>/dev/null/home.If you want to analyze later:
sudo du -ahx / | sort -rh > large_files.txtThen open it:
less large_files.txtCheck logs:
sudo du -sh /var/log/*sudo journalctl --vacuum-time=7d # Keep logs for 7 daysCheck package cache:
sudo du -sh /var/cache/aptsudo apt cleanCheck old kernels:
dpkg --list | grep linux-imagesudo apt remove --purge linux-image-OLD-VERSIONLinux provides a vast collection of security tools for penetration testing, network analysis, and system hardening. This guide covers essential tools with installation steps and example usage.
Nmap is a powerful tool for discovering hosts and services on a network.
sudo apt update && sudo apt install nmap -ynmap <target-ip>nmap 192.168.1.0/24nmap -A <target-ip>Wireshark captures and inspects network traffic in real time.
sudo apt install wireshark -ywiresharksudo tshark -i eth0Metasploit is a tool for discovering, exploiting, and validating vulnerabilities.
sudo apt install metasploit-framework -ymsfconsole
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS <target-ip>
exploitHashcat is a high-speed password recovery tool.
sudo apt install hashcat -yhashcat -m 0 -a 0 hashes.txt rockyou.txtJohn the Ripper is another tool for brute-force password attacks.
sudo apt install john -yjohn --wordlist=/usr/share/wordlists/rockyou.txt hashes.txtLynis performs system audits to detect security weaknesses.
sudo apt install lynis -ysudo lynis audit systemFail2Ban monitors logs and bans IPs after multiple failed login attempts.
sudo apt install fail2ban -ysudo systemctl enable --now fail2banUFW is a simple tool for managing iptables firewall rules.
sudo apt install ufw -ysudo ufw enablesudo ufw allow sshsudo ufw statusSuricata is an advanced intrusion detection system.
sudo apt install suricata -ysudo systemctl enable --now suricataChkrootkit scans the system for known rootkits.
sudo apt install chkrootkit -ysudo chkrootkitRkhunter detects rootkits, backdoors, and local exploits.
sudo apt install rkhunter -ysudo rkhunter --checkThese tools help enhance Linux security, detect vulnerabilities, and prevent attacks. Regularly updating and using these tools can significantly improve your system’s defense against cyber threats.
π Stay secure and keep learning!
On Debian and Ubuntu use the following command
sudo apt install usbmuxd libimobiledevice6 libimobiledevice-utils ifuse
On Fedora or RHEL
sudo dnf install libimobiledevice ifuse usbmuxd
Hardening Kali Linux is essential for maintaining security, especially since it is a penetration testing distro that can be a target for attackers.
It is not explicitly associated with security but it affects it implicitly.
In addition to this it affects the stability of whole system.
deb https://kali.download kali-last-snapshot <keep others here>Ensure your system is always updated with the latest security patches.
sudo apt update && sudo apt full-upgrade -yFor kernel updates:
sudo apt dist-upgrade -yRemove unnecessary packages:
sudo apt autoremove -y && sudo apt cleanKali uses kali as the default user. Ensure root login is disabled.
sudo passwd -l rootUse a strong password or configure password complexity policies:
sudo apt install libpam-pwquality
sudo nano /etc/security/pwquality.confModify:
minlen = 12
dcredit = -1
ucredit = -1
lcredit = -1
ocredit = -1sudo apt install libpam-google-authenticator
google-authenticatorConfigure /etc/pam.d/sshd:
auth required pam_google_authenticator.soRestart SSH:
sudo systemctl restart sshEdit SSH config:
sudo nano /etc/ssh/sshd_configModify:
PermitRootLogin no
PasswordAuthentication no
PermitEmptyPasswords no
UsePAM yes
MaxAuthTries 3
AllowUsers your_usernameRestart SSH:
sudo systemctl restart sshsudo apt install ufw -y
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp # If using SSH
sudo ufw enable
sudo ufw status verboseAppArmor (default in Kali):
sudo apt install apparmor apparmor-profiles apparmor-utils -y
sudo systemctl enable --now apparmorFor SELinux (optional):
sudo apt install selinux-basics selinux-policy-default auditd -y
sudo selinux-activate
sudo rebootEdit:
sudo nano /etc/apt/apt.conf.d/20auto-upgradesAdd:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";List enabled services:
systemctl list-unit-files --type=service | grep enabledDisable unneeded ones:
sudo systemctl disable avahi-daemon
sudo systemctl disable bluetooth
sudo systemctl disable cupsEdit GRUB:
sudo nano /etc/default/grubModify:
GRUB_CMDLINE_LINUX="ipv6.disable=1"Update GRUB:
sudo update-grub && sudo rebootecho "net.ipv4.tcp_syncookies = 1" | sudo tee -a /etc/sysctl.confecho "net.ipv4.icmp_echo_ignore_all = 1" | sudo tee -a /etc/sysctl.confApply changes:
sudo sysctl -pPrevent unauthorized access by setting a GRUB password:
sudo grub-mkpasswd-pbkdf2Copy the generated hash and add it to /etc/grub.d/40_custom:
sudo nano /etc/grub.d/40_customAdd:
set superusers="root"
password_pbkdf2 root <hashed-password>Update GRUB:
sudo update-grubEncrypt a partition:
sudo cryptsetup luksFormat /dev/sdX
sudo cryptsetup luksOpen /dev/sdX secure_dataFor full disk encryption, use LUKS during installation.
sudo apt install aide -y
sudo aideinit
sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.dbCheck system integrity:
sudo aide --checksudo apt install tripwire -yInitialize and configure rules.
sudo nano /etc/logrotate.confEnsure logs are rotated and archived.
sudo apt install auditd -y
sudo systemctl enable --now auditdCheck logs:
sudo ausearch -m avcTo disable USB storage:
echo "blacklist usb-storage" | sudo tee /etc/modprobe.d/usb-storage.confApply changes:
sudo update-initramfs -u && sudo rebootCtrl + Alt + L).sudo apt install firejail -y
firejail --seccomp firefoxEdit /etc/fstab:
sudo nano /etc/fstabAdd:
tmpfs /tmp tmpfs defaults,noexec,nosuid 0 0For encrypted swap:
sudo apt install cryptsetup -y
sudo cryptsetup luksFormat /dev/sdX
sudo cryptsetup luksOpen /dev/sdX swap
mkswap /dev/mapper/swap
swapon /dev/mapper/swapSince Kali comes with many tools, remove what you donβt use:
sudo apt remove wireshark metasploit-framework -yFor better anonymity:
sudo nano /etc/NetworkManager/conf.d/wifi_scan-rand-mac.confAdd:
[device]
wifi.scan-rand-mac-address=yesRestart NetworkManager:
sudo systemctl restart NetworkManagerConsider using the grsecurity or linux-hardened kernel.
=======================================
GNOME’s tracker is a CPU and privacy hog. There’s a pretty good case as to why it’s neither useful nor necessary here: http://lduros.net/posts/tracker-sucks-thanks-tracker/
After discovering it chowing 2 cores, I decided to go about disabling it.
~/.cache/tracker
~/.local/share/trackerAfter wiping and letting it do a fresh index on my almost new desktop, the total size of each of these directories was a whopping 3.9 GB!
On my Ubuntu GNOME setup, I found the following files:
$ ls /etc/xdg/autostart/tracker-*
/etc/xdg/autostart/tracker-extract.desktop
/etc/xdg/autostart/tracker-miner-fs.desktop
/etc/xdg/autostart/tracker-store.desktop
/etc/xdg/autostart/tracker-miner-apps.desktop
/etc/xdg/autostart/tracker-miner-user-guides.desktopYou can disable these by adding Hidden=true to them. It’s best done in your
local .config directory because 1) you don’t need sudo and 2) you are pretty
much guaranteed that your changes won’t be blown away by an update.
tracker BinaryRunning tracker will give you a vast array of tools to check on tracker and
manage its processes.
$ tracker
usage: tracker [--version] [--help]
<command> [<args>]
Available tracker commands are:
daemon Start, stop, pause and list processes responsible for indexing content
info Show information known about local files or items indexed
index Backup, restore, import and (re)index by MIME type or file name
reset Reset or remove index and revert configurations to defaults
search Search for content indexed or show content by type
sparql Query and update the index using SPARQL or search, list and tree the ontology
sql Query the database at the lowest level using SQL
status Show the indexing progress, content statistics and index state
tag Create, list or delete tags for indexed content
See 'tracker help <command>' to read about a specific subcommand.This disables everything but tracker-store, which even though it has a
.desktop file, seems tenacious and starts up anyway. However, nothing gets
indexed.
tracker daemon -t
cd ~/.config/autostart
cp -v /etc/xdg/autostart/tracker-*.desktop ./
for FILE in tracker-*.desktop; do echo Hidden=true >> $FILE; done
rm -rf ~/.cache/tracker ~/.local/share/trackerNote that tracker daemon -t is for graceful termination. If you are having
issues terminating processes or just want to take your frustration out,
tracker daemon -k immediately kills all processes.
After this is done, tracker-store will still start on the next boot. However,
nothing will be indexed. Your disk and CPU will be better for wear.
$ tracker status
Currently indexed: 0 files, 0 folders
Remaining space on database partition: 123 GB (78.9%)
All data miners are idle, indexing complete