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 -20
sudo du -sh /home/* 2>/dev/null
/home
.If you want to analyze later:
sudo du -ahx / | sort -rh > large_files.txt
Then open it:
less large_files.txt
Check logs:
sudo du -sh /var/log/*
sudo journalctl --vacuum-time=7d # Keep logs for 7 days
Check package cache:
sudo du -sh /var/cache/apt
sudo apt clean
Check old kernels:
dpkg --list | grep linux-image
sudo apt remove --purge linux-image-OLD-VERSION
Linux 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 -y
nmap <target-ip>
nmap 192.168.1.0/24
nmap -A <target-ip>
Wireshark captures and inspects network traffic in real time.
sudo apt install wireshark -y
wireshark
sudo tshark -i eth0
Metasploit is a tool for discovering, exploiting, and validating vulnerabilities.
sudo apt install metasploit-framework -y
msfconsole
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS <target-ip>
exploit
Hashcat is a high-speed password recovery tool.
sudo apt install hashcat -y
hashcat -m 0 -a 0 hashes.txt rockyou.txt
John the Ripper is another tool for brute-force password attacks.
sudo apt install john -y
john --wordlist=/usr/share/wordlists/rockyou.txt hashes.txt
Lynis performs system audits to detect security weaknesses.
sudo apt install lynis -y
sudo lynis audit system
Fail2Ban monitors logs and bans IPs after multiple failed login attempts.
sudo apt install fail2ban -y
sudo systemctl enable --now fail2ban
UFW is a simple tool for managing iptables firewall rules.
sudo apt install ufw -y
sudo ufw enable
sudo ufw allow ssh
sudo ufw status
Suricata is an advanced intrusion detection system.
sudo apt install suricata -y
sudo systemctl enable --now suricata
Chkrootkit scans the system for known rootkits.
sudo apt install chkrootkit -y
sudo chkrootkit
Rkhunter detects rootkits, backdoors, and local exploits.
sudo apt install rkhunter -y
sudo rkhunter --check
These 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 -y
For kernel updates:
sudo apt dist-upgrade -y
Remove unnecessary packages:
sudo apt autoremove -y && sudo apt clean
Kali uses kali
as the default user. Ensure root login is disabled.
sudo passwd -l root
Use a strong password or configure password complexity policies:
sudo apt install libpam-pwquality
sudo nano /etc/security/pwquality.conf
Modify:
minlen = 12
dcredit = -1
ucredit = -1
lcredit = -1
ocredit = -1
sudo apt install libpam-google-authenticator
google-authenticator
Configure /etc/pam.d/sshd
:
auth required pam_google_authenticator.so
Restart SSH:
sudo systemctl restart ssh
Edit SSH config:
sudo nano /etc/ssh/sshd_config
Modify:
PermitRootLogin no
PasswordAuthentication no
PermitEmptyPasswords no
UsePAM yes
MaxAuthTries 3
AllowUsers your_username
Restart SSH:
sudo systemctl restart ssh
sudo 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 verbose
AppArmor (default in Kali):
sudo apt install apparmor apparmor-profiles apparmor-utils -y
sudo systemctl enable --now apparmor
For SELinux (optional):
sudo apt install selinux-basics selinux-policy-default auditd -y
sudo selinux-activate
sudo reboot
Edit:
sudo nano /etc/apt/apt.conf.d/20auto-upgrades
Add:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
List enabled services:
systemctl list-unit-files --type=service | grep enabled
Disable unneeded ones:
sudo systemctl disable avahi-daemon
sudo systemctl disable bluetooth
sudo systemctl disable cups
Edit GRUB:
sudo nano /etc/default/grub
Modify:
GRUB_CMDLINE_LINUX="ipv6.disable=1"
Update GRUB:
sudo update-grub && sudo reboot
echo "net.ipv4.tcp_syncookies = 1" | sudo tee -a /etc/sysctl.conf
echo "net.ipv4.icmp_echo_ignore_all = 1" | sudo tee -a /etc/sysctl.conf
Apply changes:
sudo sysctl -p
Prevent unauthorized access by setting a GRUB password:
sudo grub-mkpasswd-pbkdf2
Copy the generated hash and add it to /etc/grub.d/40_custom
:
sudo nano /etc/grub.d/40_custom
Add:
set superusers="root"
password_pbkdf2 root <hashed-password>
Update GRUB:
sudo update-grub
Encrypt a partition:
sudo cryptsetup luksFormat /dev/sdX
sudo cryptsetup luksOpen /dev/sdX secure_data
For 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.db
Check system integrity:
sudo aide --check
sudo apt install tripwire -y
Initialize and configure rules.
sudo nano /etc/logrotate.conf
Ensure logs are rotated and archived.
sudo apt install auditd -y
sudo systemctl enable --now auditd
Check logs:
sudo ausearch -m avc
To disable USB storage:
echo "blacklist usb-storage" | sudo tee /etc/modprobe.d/usb-storage.conf
Apply changes:
sudo update-initramfs -u && sudo reboot
Ctrl + Alt + L
).sudo apt install firejail -y
firejail --seccomp firefox
Edit /etc/fstab
:
sudo nano /etc/fstab
Add:
tmpfs /tmp tmpfs defaults,noexec,nosuid 0 0
For 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/swap
Since Kali comes with many tools, remove what you donβt use:
sudo apt remove wireshark metasploit-framework -y
For better anonymity:
sudo nano /etc/NetworkManager/conf.d/wifi_scan-rand-mac.conf
Add:
[device]
wifi.scan-rand-mac-address=yes
Restart NetworkManager:
sudo systemctl restart NetworkManager
Consider 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/tracker
After 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.desktop
You 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/tracker
Note 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