Linux Guide
Linux Guide
11 Topics
Permissions & Ownership Package Management
Linkedin.com/in/ahmedhamza15
This guide provides a practical reference for the most commonly used Linux system
administration commands, covering file permissions, networking tools, service
management, logs, and remote access utilities and more.
The Contents
1. chmod
chmod -R 755 /var/www/html
Apply changes recursively (to subdirectories and files)
chmod -c 751 HR
Apply rwxr-x--x on the directory (-c like verbos)
2. chgrp
chgrp IT /root/DIR
Change the group of /root/DIR to IT
3.chown
chown -R root:IT /root/file.txt
This changes the group of /root/file.txt to root:IT and
operate on files and directories recursively. (This option does not follow
symbolic links unless combined with -h, -H, -L, or -P)
4. umask
umask – the utility umask is used to set the default permissions for files or
directories the user creates. (umask works by Bitwise Algorithm)
umask 0022 – First 0 is called the sticky bit (special security feature), the
remaining three digits 022 are the octal values of the umask for a file or
directory [0-2-2 = user-group-others]
• For a file (default: 666) - {002 means 664} {022 means 644} {000
means 666} and so on.
• For a directory (default: 777) - {002 means 775} {022 means 055}
{000 means 777} and so on.
Umask 0543
This changes the default umask to 543, means default perm for file and dir
will be
[for files: 123 = --x-w--wx (the real will be 224 not 123)] [for directories:
234 = -w--wxr--]
Note: it will be 224 not 123, because of x -means execute-, files can’t get
execute bits (x) by default. so it will be converted from 001=1=x to
010=2=w, and for group it stills w, and for others it will be converted from
011=3=-wx to 100=4=r)
Package Management
Debian-based Systems
Note:
• In 1998, apt-get was released with the Debian 2.0 "Hamm"
distribution as a command-line tool for managing packages. In 2015,
the more user-friendly apt command was introduced with Debian 8
"Jessie", combining the functionalities of apt-get, apt-cache,
and others. Today, apt is preferred for day-to-day interactive use,
while apt-get remains essential for scripts due to its stable behavior.
Note:
• Most modern Linux systems use Systemd
1. Systemd – systemctl
systemctl
Show all active units (not just services)
ip addr show
Show the IP addresses assigned to all network interfaces
ip link
Display information about network interfaces
ip route show
Display the routing table
ip neigh show
Show the current ARP cache
ip -6 addr show
Display IPv6 address (Same as IPv4 but use -6 for IPv6)
ifconfig
Show status of the currently active interfaces (or given interface like
ifconig eth0)
ifconfig -a
Show the status of all interfaces, both up and down
ifconfig -s
display a short list (like netstat -i)
ifconfig up eth0
For activating/deactivating (up/down) an interface
2. netplan – Manage network configuration for network interfaces
(especially on Ubuntu 18.04 and newer).
Edit /etc/netplan/00-installer-config.yaml to define
network configuration
To enable or disable DHCP, you would need to interact with the network
configuration tools (Netplan, NetworkManager, systemd-
networkd, or /etc/network/interfaces), not the ip or
ifconfig tools. If you want to get or release a DHCP lease on an
interface manually, you can use
dhclient.
dhclient eth0
Enable DHCP (request a DHCP lease)
dhclient -r eth0
Release DHCP lease
Object Description
general Show overall NetworkManager status
device Manage physical & virtual devices
connection Manage network connection profiles
networking Enable/disable all networking
radio Manage wireless radios (Wi-Fi, WWAN)
1. ping
ping google.com Send ICMP packets to test connection
ping -c 4 google.com Send a specific number of packets
ping -i 5 google.com Set interval between packets (in
seconds)
ping -W 10 google.com Set timeout for a reply
ping -s 1400 google.com Set packet size (in byte)
2. Traceroute
traceroute google.com
traceroute -n google.com
Show IPs only – no DNS resolving (faster)
traceroute -w 10 google.com
Timeout for each reply (in secs)
traceroute -m 7 google.com
Set maximum hops (or maximum TTLs) to max_hops instead of 30
tracepath
(RHEL command instead of traceroute)
wget https://example.com/file.zip
Download with default options
wget --no-check-certificate
https://example.com/file.zip
Ignore invalid SSL
wget -q https://example.com/file.zip
Quit mode
Open/Close Ports
firewall-cmd --zone=public --add-port=8080/tcp
firewall-cmd --reload
firewall-cmd --reload
firewall-cmd --reload
firewall-cmd --reload
dig -x 8.8.8.8
Performs a reverse DNS lookup to resolve an IP address to a domain
name
nslookup example.com
Performs a DNS query for a domain
nslookup
In interactive mode type a specific record type, for ex: set type=MX
example.com
host -a example.com
Specifies the type of record to query (A, MX, NS, etc.)
host -C example.com
Specifies the type of record to query (A, MX, NS, etc.)
Look at man host or host --help to see other options
Disk & Partition Management
[Tools: df, du, lsblk, fdisk, mount]
df -h
Check disk usage (-h human-readable)
df --block-size=1G
Show only 1G-blocks (can use in Giga to show 1M-blocks in Miga)
df -hT
Print file system type
df -h --type=TYPE
Print this file system type TYPE
(for ex: df -h --type=xfs OR df -h --type=xfs,tmpfs)
df -h --exclude-type=TYPE
Exclude this file syste type TYPE to file systems not of type TYPE
(for ex: df -h --exclude-type=xfs)
du -sh /home
Check directory size (-s summarize total size, -h human-readable)
du -sh -a HR
Write counts for all files, not just HR directory or directories
du -sh /* 2>/dev/null
Check largest directories
Mount a USB/Drive
Mounting: Attaching a filesystem (like a USB or a second drive) to a
directory (e.g., /mnt/usb)
1- Insert USB (or attach secondary disk)
2- Check with lsblk or fdisk -l:
lsblk -m
Output info about devices owner, group and mode, (is equivalent to
-o NAME,SIZE,OWNER,GROUP,MODE)
3. mount
mkdir /mnt/usb
mount /dev/sdb1 /mnt/usb
This mount the driver /dev/sbd1 to mnt/usb
unmount /dev/sdb1
This unmount /dev/sbd1 - also can use unmount /mnt/usb
* * * * * <command_to_run>
| | | | |
| | | | |______ Day of the week (0-7) (0=Sunday)
| | | |_________ Month (1-12)
| | |___________ Day of month (1-31)
| |____________ _ Hour (0-23) (0=12AM)
|________________ Minute (0-59)
Commands used:
tail -f Live monitoring - follow log updates
cat / less / more View logs statically
grep Filter and search log entires
dmesg View kernel messages (boot &
hardware)
dmseg | grep disk Filter "disk" plug-in events or issues
journalctl Modern log viewer for systemd systems
- view all logs
journalctl -xe Show recent errors
journalctl -b Logs since last boot
SSH & Remote Access
SSH (Secure Shell)
• Is a network protocol used to securely connect to remote systems.
• It’s essential for managing servers, especially headless ones (no
graphical interface).
• SSH works by connecting a client program to an SSH server, called
sshd
Note:
-Replace server1 with the user you're connecting to.
-Replace 192.168.88.110 with the remote machine’s IP you connect
to
4. rsync
rsync – a fast, versatile, remote (and local) file-copying tool (for more
efficient transfers)
touch ~/.ssh/config
Create the config file
chmod 600 ~/.ssh/config
Change permissions of config file to -rw------- (only user can read
and write)
The config file is only for easy logging, without having to type long
commands like [email protected]
6. SSH Agent
Use SSH agent for managing keys
• ssh-agent – A background program that holds your private keys
in memory.
• Use it when your private key has a passphrase, and you don’t want to
type it every time.
• Works until you reboot or stop the agent.
Warning:
• Be careful working with firewalls; take care not to lock yourself
out of ssh session when deleting rules.
PasswordAuthentication no
Disable password login (enforce key-based login – high secure)
AllowUsers username
Allow only specific users to connect via SSH
Note:
• sshd_config Is for the SSH server (daemon) behavior
• ssh_config Is for the SSH client (user connection
behavior)
~/.ssh/authorize_keys
Stores public keys allowed for that user
~/.ssh/id_rsa
Private and public key pair (can be another name too)
~/.ssh/id_rsa.pub
Private and public key pair (can be another name too)
~/.ssh/known_hosts
List of previously connected servers' fingerprints
Example:
In ~/.ssh/config (SSH Client — per user)
Host server1
HostName 192.168.88.110
User yourusername
Port 2222
IdentityFile ~/.ssh/id_rsa
This allows you to just type ssh server1 instead of the full command
Installing SSH:
apt install openssh-server Ubuntu/Debian
dnf install openssh-server REHL 8+ (for older use yum)
yum install openssh-server CentOS 7