Linux Admin 1 Commands
Linux Admin 1 Commands
VIM
Insert Mode
i Open insert mode and write
before the cursor
a Open insert mode and write
after the cursor
A Open insert mode and
move the cursor to the end
of the line
I Open insert mode and
move the cursor to the start
of the line
o Open insert mode and make
a new line after line I stop
on it
O Open insert mode and make
a new line before the line I
stop on it
Extend Mode
:wq Save and exit the current
line
:x Save the file if it is not saved
then quit
:w Save and remain in the
editor
:q Quit the current file if there
are no unsaved changes
:qi Quite and ignore any
unsaved changes
:10 Jump to line number 10
/etc/login.defs
The file that exists id for
users
Super User 0 root
System User 1-200 Assigned statically to system process by
RedHat
System User 201-999 Dynamic range to any system account
created in the system
Regular User 1000 - 6000
Password Parameters
chage + options + user -m Mini days are required after the
password is changed to enable the
change password again
chage -m 0 ali
disable it
Example
chage -m 0 -M 40 -W 7 -l 14 Ali
Every option shows in /etc/shadow
Special Permissions
1. Top -d 2
Will refresh every 2 seconds
Installing Packages
Install a specific package:
sudo apt install <package_name>
Install multiple packages at once:
sudo apt install <package1> <package2>
Removing Packages
Remove a specific package (but leave its configuration files):
sudo apt remove <package_name>
Remove a package and its configuration files:
sudo apt purge <package_name>
Remove unused packages automatically (cleanup after
installing/removing software):
sudo apt autoremove
Cleaning Up
Remove downloaded package files:
sudo apt clean
Remove only old package versions from the cache:
sudo apt autoclean
2. apt-get
apt-get is an older package management tool, which is still available and
widely used for scripting and advanced purposes.
Updating Package Lists
Update the package list:
sudo apt-get update
Upgrading Packages
Upgrade installed packages:
sudo apt-get upgrade
Upgrade and handle package dependencies:
sudo apt-get dist-upgrade
Installing and Removing Packages
Install a package:
sudo apt-get install <package_name>
Remove a package:
sudo apt-get remove <package_name>
Purge a package (removes package and configuration files):
sudo apt-get purge <package_name>
Automatically remove unused packages:
sudo apt-get autoremove
Installing Packages
Install a specific package:
sudo dnf install <package_name>
Install multiple packages at once:
sudo dnf install <package1> <package2>
Removing Packages
Remove a package:
sudo dnf remove <package_name>
Remove a package and its dependencies (those not required by other
packages):
sudo dnf autoremove <package_name>
Searching for Packages
Search for a package by name or description:
sudo dnf search <package_name_or_keyword>
List information about a specific package:
sudo dnf info <package_name>
Listing Installed Packages
List all installed packages:
sudo dnf list installed
List all available packages:
sudo dnf list available
Group Management
Install a package group (e.g., Development Tools):
sudo dnf group install "Development Tools"
List available package groups:
sudo dnf group list
Remove a package group:
sudo dnf group remove "Development Tools"
Cleaning Up
Remove cached packages and metadata:
sudo dnf clean all
4. Repository Management
Enable or Disable Repositories
Enable a repository temporarily:
sudo dnf --enablerepo=<repo_name> install <package_name>
Disable a repository temporarily:
sudo dnf --disablerepo=<repo_name> install <package_name>
List enabled repositories:
sudo dnf repolist
List all repositories (enabled and disabled):
sudo dnf repolist all
Adding and Removing Repositories
Add a repository by creating a .repo file in /etc/yum.repos.d/ with
appropriate configuration. For example:
sudo nano /etc/yum.repos.d/example.repo
Inside the file:
ini
[example]
name=Example Repository
baseurl=http://example.com/repo
enabled=1
gpgcheck=1
gpgkey=http://example.com/repo/RPM-GPG-KEY-example
Remove a repository by deleting its .repo file:
sudo rm /etc/yum.repos.d/example.repo
Configure Routing
Display routing table:
ip route show = ip route = route (apt install net-tools)
Add a route:
sudo ip route add 192.168.1.0/24 via 192.168.1.1
Delete a route:
sudo ip route del 192.168.1.0/24
Netcat (nc)
Check if a specific port is open:
nc -zv google.com 80
Start a simple TCP server:
nc -l 1234
Connect to a TCP server:
nc 192.168.1.1 1234
Telnet
Test a TCP connection to a port:
telnet google.com 80
Dig / nslookup
Query DNS information:
o dig (more powerful, preferred tool):
dig google.com
o nslookup (older tool):
nslookup google.com
Get DNS records (e.g., MX records):
dig google.com MX
Host
Find the IP address for a domain name:
host google.com
Nmap
Network scanning and discovery:
o Basic scan of open ports:
sudo nmap google.com
o Scan a specific port range:
sudo nmap -p 1-100 google.com
o If nmap is not installed:
sudo apt install nmap
SS (Socket Statistics)
Display socket and network connection information (replacement for
netstat):
ss -tuln
-t: Shows TCP connections.
-u: Shows UDP connections.
-l: Shows only listening sockets.
-n: Shows numerical addresses instead of resolving hostnames.
Wireshark
Graphical network protocol analyzer (GUI tool):
wireshark
If wireshark is not installed:
sudo apt install wireshark
4. Network Interface Configuration
These commands help configure interfaces manually.
DHCP Management
Renew a DHCP lease:
sudo dhclient eth0
Modify Hostname
View current hostname:
hostnamectl
Change hostname:
sudo hostnamectl set-hostname new_hostname
Modify /etc/hosts
Edit /etc/hosts to map domain names to IP addresses:
sudo nano /etc/hosts
5. Firewall Configuration
These commands manage firewall rules.
Iptables
List all current rules:
sudo iptables -L
Add a rule to allow traffic on port 80:
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
Block traffic from a specific IP:
sudo iptables -A INPUT -s 192.168.1.100 -j DROP
If iptables is not installed:
sudo apt install iptables